TFTP.h

Go to the documentation of this file.
00001 // @(#)root/net:$Id: TFTP.h 23091 2008-04-09 15:04:27Z rdm $
00002 // Author: Fons Rademakers   13/02/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TFTP
00013 #define ROOT_TFTP
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TFTP                                                                 //
00018 //                                                                      //
00019 // This class provides all infrastructure for a performant file         //
00020 // transfer protocol. It works in conjuction with the rootd daemon      //
00021 // and can use parallel sockets to improve performance over fat pipes.  //
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;        // FQDN of remote host
00046    TString    fUser;        // remote user
00047    Int_t      fPort;        // port to which to connect
00048    Int_t      fParallel;    // number of parallel sockets
00049    Int_t      fWindowSize;  // tcp window size used
00050    Int_t      fProtocol;    // rootd protocol level
00051    Int_t      fLastBlock;   // last block successfully transfered
00052    Int_t      fBlockSize;   // size of data buffer used to transfer
00053    Int_t      fMode;        // binary or ascii file transfer mode
00054    Long64_t   fRestartAt;   // restart transmission at specified offset
00055    TString    fCurrentFile; // file currently being get or put
00056    TSocket   *fSocket;      //! connection to rootd
00057    Long64_t   fBytesWrite;  // number of bytes sent
00058    Long64_t   fBytesRead;   // number of bytes received
00059    Bool_t     fDir;         // Indicates if a remote directory is open
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 &);              // not implemented
00066    void   operator=(const TFTP &);  // idem
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;  //number of bytes sent by all TFTP objects
00073    static Long64_t fgBytesRead;   //number of bytes received by all TFTP objects
00074 
00075 public:
00076    enum {
00077       kDfltBlockSize  = 0x80000,   // 512KB
00078       kDfltWindowSize = 65535,     // default tcp buffer size
00079       kBinary         = 0,         // binary data transfer (default)
00080       kAscii          = 1          // ascii data transfer
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    // standard ftp equivalents...
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)  // File Transfer Protocol class using rootd
00134 };
00135 
00136 #endif

Generated on Tue Jul 5 14:26:56 2011 for ROOT_528-00b_version by  doxygen 1.5.1