Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TFTP.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/net:$Id$
0002 // Author: Fons Rademakers   13/02/2001
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TFTP
0013 #define ROOT_TFTP
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TFTP                                                                 //
0018 //                                                                      //
0019 // This class provides all infrastructure for a performant file         //
0020 // transfer protocol. It works in conjuction with the rootd daemon      //
0021 // and can use parallel sockets to improve performance over fat pipes.  //
0022 //                                                                      //
0023 //////////////////////////////////////////////////////////////////////////
0024 
0025 #include "TObject.h"
0026 #include "TSystem.h"
0027 #include "TString.h"
0028 #include "MessageTypes.h"
0029 
0030 
0031 class TSocket;
0032 
0033 
0034 class TFTP : public TObject {
0035 
0036 private:
0037    TString    fHost;        // FQDN of remote host
0038    TString    fUser;        // remote user
0039    Int_t      fPort;        // port to which to connect
0040    Int_t      fParallel;    // number of parallel sockets
0041    Int_t      fWindowSize;  // tcp window size used
0042    Int_t      fProtocol;    // rootd protocol level
0043    Int_t      fLastBlock;   // last block successfully transfered
0044    Int_t      fBlockSize;   // size of data buffer used to transfer
0045    Int_t      fMode;        // binary or ascii file transfer mode
0046    Long64_t   fRestartAt;   // restart transmission at specified offset
0047    TString    fCurrentFile; // file currently being get or put
0048    TSocket   *fSocket;      //! connection to rootd
0049    Long64_t   fBytesWrite;  // number of bytes sent
0050    Long64_t   fBytesRead;   // number of bytes received
0051    Bool_t     fDir;         // Indicates if a remote directory is open
0052 
0053    TFTP(): fHost(), fUser(), fPort(0), fParallel(0), fWindowSize(0),
0054       fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
0055       fRestartAt(0), fCurrentFile(), fSocket(nullptr), fBytesWrite(0),
0056       fBytesRead(0), fDir(kFALSE) { }
0057    TFTP(const TFTP &) = delete;
0058    void   operator=(const TFTP &) = delete;
0059    void   Init(const char *url, Int_t parallel, Int_t wsize);
0060    void   PrintError(const char *where, Int_t err) const;
0061    Int_t  Recv(Int_t &status, EMessageTypes &kind) const;
0062    void   SetMode(Int_t mode) { fMode = mode; }
0063 
0064    static Long64_t fgBytesWrite;  //number of bytes sent by all TFTP objects
0065    static Long64_t fgBytesRead;   //number of bytes received by all TFTP objects
0066 
0067 public:
0068    enum {
0069       kDfltBlockSize  = 0x80000,   // 512KB
0070       kDfltWindowSize = 65535,     // default tcp buffer size
0071       kBinary         = 0,         // binary data transfer (default)
0072       kAscii          = 1          // ascii data transfer
0073    };
0074 
0075    TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
0076         TSocket *sock = nullptr);
0077    virtual ~TFTP();
0078 
0079    void     SetBlockSize(Int_t blockSize);
0080    Int_t    GetBlockSize() const { return fBlockSize; }
0081    void     SetRestartAt(Long64_t at) { fRestartAt = at; }
0082    Long64_t GetRestartAt() const { return fRestartAt; }
0083    Int_t    GetMode() const { return fMode; }
0084 
0085    Bool_t   IsOpen() const { return fSocket ? kTRUE : kFALSE; }
0086    void     Print(Option_t *opt = "") const override;
0087 
0088    Long64_t PutFile(const char *file, const char *remoteName = nullptr);
0089    Long64_t GetFile(const char *file, const char *localName = nullptr);
0090 
0091    Bool_t   AccessPathName(const char *path, EAccessMode mode = kFileExists,
0092                            Bool_t print = kFALSE);
0093    const char *GetDirEntry(Bool_t print = kFALSE);
0094    Int_t    GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
0095    Int_t    ChangeDirectory(const char *dir) const;
0096    Int_t    MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
0097    Int_t    DeleteDirectory(const char *dir) const;
0098    Int_t    ListDirectory(Option_t *cmd = "") const;
0099    void     FreeDirectory(Bool_t print = kFALSE);
0100    Bool_t   OpenDirectory(const char *name, Bool_t print = kFALSE);
0101    Int_t    PrintDirectory() const;
0102    Int_t    RenameFile(const char *file1, const char *file2) const;
0103    Int_t    DeleteFile(const char *file) const;
0104    Int_t    ChangePermission(const char *file, Int_t mode) const;
0105    Int_t    Close();
0106    void     Binary() { SetMode(kBinary); }
0107    void     Ascii() { SetMode(kAscii); }
0108    TSocket *GetSocket() const { return fSocket; }
0109 
0110    // standard ftp equivalents...
0111    void put(const char *file, const char *remoteName = nullptr) { PutFile(file, remoteName); }
0112    void get(const char *file, const char *localName = nullptr) { GetFile(file, localName); }
0113    void cd(const char *dir) const { ChangeDirectory(dir); }
0114    void mkdir(const char *dir) const { MakeDirectory(dir); }
0115    void rmdir(const char *dir) const { DeleteDirectory(dir); }
0116    void ls(Option_t *cmd = "") const override { ListDirectory(cmd); }
0117    void pwd() const { PrintDirectory(); }
0118    void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
0119    void rm(const char *file) const { DeleteFile(file); }
0120    void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
0121    void bye() { Close(); }
0122    void bin() { Binary(); }
0123    void ascii() { Ascii(); }
0124 
0125    ClassDefOverride(TFTP, 1)  // File Transfer Protocol class using rootd
0126 };
0127 
0128 #endif