00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TFTP
00013 #define ROOT_TFTP
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef ROOT_TObject
00026 #include "TObject.h"
00027 #endif
00028 #ifndef ROOT_TSystem
00029 #include "TSystem.h"
00030 #endif
00031 #ifndef ROOT_TString
00032 #include "TString.h"
00033 #endif
00034 #ifndef ROOT_MessageTypes
00035 #include "MessageTypes.h"
00036 #endif
00037
00038
00039 class TSocket;
00040
00041
00042 class TFTP : public TObject {
00043
00044 private:
00045 TString fHost;
00046 TString fUser;
00047 Int_t fPort;
00048 Int_t fParallel;
00049 Int_t fWindowSize;
00050 Int_t fProtocol;
00051 Int_t fLastBlock;
00052 Int_t fBlockSize;
00053 Int_t fMode;
00054 Long64_t fRestartAt;
00055 TString fCurrentFile;
00056 TSocket *fSocket;
00057 Long64_t fBytesWrite;
00058 Long64_t fBytesRead;
00059 Bool_t fDir;
00060
00061 TFTP(): fHost(), fUser(), fPort(0), fParallel(0), fWindowSize(0),
00062 fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
00063 fRestartAt(0), fCurrentFile(), fSocket(0), fBytesWrite(0),
00064 fBytesRead(0), fDir(kFALSE) { }
00065 TFTP(const TFTP &);
00066 void operator=(const TFTP &);
00067 void Init(const char *url, Int_t parallel, Int_t wsize);
00068 void PrintError(const char *where, Int_t err) const;
00069 Int_t Recv(Int_t &status, EMessageTypes &kind) const;
00070 void SetMode(Int_t mode) { fMode = mode; }
00071
00072 static Long64_t fgBytesWrite;
00073 static Long64_t fgBytesRead;
00074
00075 public:
00076 enum {
00077 kDfltBlockSize = 0x80000,
00078 kDfltWindowSize = 65535,
00079 kBinary = 0,
00080 kAscii = 1
00081 };
00082
00083 TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
00084 TSocket *sock = 0);
00085 virtual ~TFTP();
00086
00087 void SetBlockSize(Int_t blockSize);
00088 Int_t GetBlockSize() const { return fBlockSize; }
00089 void SetRestartAt(Long64_t at) { fRestartAt = at; }
00090 Long64_t GetRestartAt() const { return fRestartAt; }
00091 Int_t GetMode() const { return fMode; }
00092
00093 Bool_t IsOpen() const { return fSocket ? kTRUE : kFALSE; }
00094 void Print(Option_t *opt = "") const;
00095
00096 Long64_t PutFile(const char *file, const char *remoteName = 0);
00097 Long64_t GetFile(const char *file, const char *localName = 0);
00098
00099 Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists,
00100 Bool_t print = kFALSE);
00101 const char *GetDirEntry(Bool_t print = kFALSE);
00102 Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
00103 Int_t ChangeDirectory(const char *dir) const;
00104 Int_t MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
00105 Int_t DeleteDirectory(const char *dir) const;
00106 Int_t ListDirectory(Option_t *cmd = "") const;
00107 void FreeDirectory(Bool_t print = kFALSE);
00108 Bool_t OpenDirectory(const char *name, Bool_t print = kFALSE);
00109 Int_t PrintDirectory() const;
00110 Int_t RenameFile(const char *file1, const char *file2) const;
00111 Int_t DeleteFile(const char *file) const;
00112 Int_t ChangePermission(const char *file, Int_t mode) const;
00113 Int_t Close();
00114 void Binary() { SetMode(kBinary); }
00115 void Ascii() { SetMode(kAscii); }
00116 TSocket *GetSocket() const { return fSocket; }
00117
00118
00119 void put(const char *file, const char *remoteName = 0) { PutFile(file, remoteName); }
00120 void get(const char *file, const char *localName = 0) { GetFile(file, localName); }
00121 void cd(const char *dir) const { ChangeDirectory(dir); }
00122 void mkdir(const char *dir) const { MakeDirectory(dir); }
00123 void rmdir(const char *dir) const { DeleteDirectory(dir); }
00124 void ls(Option_t *cmd = "") const { ListDirectory(cmd); }
00125 void pwd() const { PrintDirectory(); }
00126 void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
00127 void rm(const char *file) const { DeleteFile(file); }
00128 void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
00129 void bye() { Close(); }
00130 void bin() { Binary(); }
00131 void ascii() { Ascii(); }
00132
00133 ClassDef(TFTP, 1)
00134 };
00135
00136 #endif