Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:23:08

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 namespace ROOT::Deprecated {
0034 
0035 class TFTP : public TObject {
0036 
0037 private:
0038    TString    fHost;        // FQDN of remote host
0039    TString    fUser;        // remote user
0040    Int_t      fPort;        // port to which to connect
0041    Int_t      fParallel;    // number of parallel sockets
0042    Int_t      fWindowSize;  // tcp window size used
0043    Int_t      fProtocol;    // rootd protocol level
0044    Int_t      fLastBlock;   // last block successfully transferred
0045    Int_t      fBlockSize;   // size of data buffer used to transfer
0046    Int_t      fMode;        // binary or ascii file transfer mode
0047    Long64_t   fRestartAt;   // restart transmission at specified offset
0048    TString    fCurrentFile; // file currently being get or put
0049    TSocket   *fSocket;      ///<! connection to rootd
0050    Long64_t   fBytesWrite;  // number of bytes sent
0051    Long64_t   fBytesRead;   // number of bytes received
0052    Bool_t     fDir;         // Indicates if a remote directory is open
0053 
0054    TFTP(): fHost(), fUser(), fPort(0), fParallel(0), fWindowSize(0),
0055       fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
0056       fRestartAt(0), fCurrentFile(), fSocket(nullptr), fBytesWrite(0),
0057       fBytesRead(0), fDir(kFALSE) { }
0058    TFTP(const TFTP &) = delete;
0059    void   operator=(const TFTP &) = delete;
0060    void   Init(const char *url, Int_t parallel, Int_t wsize);
0061    void   PrintError(const char *where, Int_t err) const;
0062    Int_t  Recv(Int_t &status, EMessageTypes &kind) const;
0063    void   SetMode(Int_t mode) { fMode = mode; }
0064 
0065    static Long64_t fgBytesWrite;  //number of bytes sent by all TFTP objects
0066    static Long64_t fgBytesRead;   //number of bytes received by all TFTP objects
0067 
0068 public:
0069    enum {
0070       kDfltBlockSize  = 0x80000,   // 512KB
0071       kDfltWindowSize = 65535,     // default tcp buffer size
0072       kBinary         = 0,         // binary data transfer (default)
0073       kAscii          = 1          // ascii data transfer
0074    };
0075 
0076    TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
0077         TSocket *sock = nullptr);
0078    virtual ~TFTP();
0079 
0080    void     SetBlockSize(Int_t blockSize);
0081    Int_t    GetBlockSize() const { return fBlockSize; }
0082    void     SetRestartAt(Long64_t at) { fRestartAt = at; }
0083    Long64_t GetRestartAt() const { return fRestartAt; }
0084    Int_t    GetMode() const { return fMode; }
0085 
0086    Bool_t   IsOpen() const { return fSocket ? kTRUE : kFALSE; }
0087    void     Print(Option_t *opt = "") const override;
0088 
0089    Long64_t PutFile(const char *file, const char *remoteName = nullptr);
0090    Long64_t GetFile(const char *file, const char *localName = nullptr);
0091 
0092    Bool_t   AccessPathName(const char *path, EAccessMode mode = kFileExists,
0093                            Bool_t print = kFALSE);
0094    const char *GetDirEntry(Bool_t print = kFALSE);
0095    Int_t    GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
0096    Int_t    ChangeDirectory(const char *dir) const;
0097    Int_t    MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
0098    Int_t    DeleteDirectory(const char *dir) const;
0099    Int_t    ListDirectory(Option_t *cmd = "") const;
0100    void     FreeDirectory(Bool_t print = kFALSE);
0101    Bool_t   OpenDirectory(const char *name, Bool_t print = kFALSE);
0102    Int_t    PrintDirectory() const;
0103    Int_t    RenameFile(const char *file1, const char *file2) const;
0104    Int_t    DeleteFile(const char *file) const;
0105    Int_t    ChangePermission(const char *file, Int_t mode) const;
0106    Int_t    Close();
0107    void     Binary() { SetMode(kBinary); }
0108    void     Ascii() { SetMode(kAscii); }
0109    TSocket *GetSocket() const { return fSocket; }
0110 
0111    // standard ftp equivalents...
0112    void put(const char *file, const char *remoteName = nullptr) { PutFile(file, remoteName); }
0113    void get(const char *file, const char *localName = nullptr) { GetFile(file, localName); }
0114    void cd(const char *dir) const { ChangeDirectory(dir); }
0115    void mkdir(const char *dir) const { MakeDirectory(dir); }
0116    void rmdir(const char *dir) const { DeleteDirectory(dir); }
0117    void ls(Option_t *cmd = "") const override { ListDirectory(cmd); }
0118    void pwd() const { PrintDirectory(); }
0119    void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
0120    void rm(const char *file) const { DeleteFile(file); }
0121    void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
0122    void bye() { Close(); }
0123    void bin() { Binary(); }
0124    void ascii() { Ascii(); }
0125 
0126    ClassDefOverride(TFTP, 1)  // File Transfer Protocol class using rootd
0127 };
0128 
0129 } // namespace ROOT::Deprecated
0130 
0131 using TFTP R__DEPRECATED(6, 42, "TFTP is deprecated") = ROOT::Deprecated::TFTP;
0132 
0133 #endif