Logo ROOT   6.10/09
Reference Guide
TFTP.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 13/02/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TFTP
13 #define ROOT_TFTP
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TFTP //
18 // //
19 // This class provides all infrastructure for a performant file //
20 // transfer protocol. It works in conjuction with the rootd daemon //
21 // and can use parallel sockets to improve performance over fat pipes. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TObject.h"
26 #include "TSystem.h"
27 #include "TString.h"
28 #include "MessageTypes.h"
29 
30 
31 class TSocket;
32 
33 
34 class TFTP : public TObject {
35 
36 private:
37  TString fHost; // FQDN of remote host
38  TString fUser; // remote user
39  Int_t fPort; // port to which to connect
40  Int_t fParallel; // number of parallel sockets
41  Int_t fWindowSize; // tcp window size used
42  Int_t fProtocol; // rootd protocol level
43  Int_t fLastBlock; // last block successfully transfered
44  Int_t fBlockSize; // size of data buffer used to transfer
45  Int_t fMode; // binary or ascii file transfer mode
46  Long64_t fRestartAt; // restart transmission at specified offset
47  TString fCurrentFile; // file currently being get or put
48  TSocket *fSocket; //! connection to rootd
49  Long64_t fBytesWrite; // number of bytes sent
50  Long64_t fBytesRead; // number of bytes received
51  Bool_t fDir; // Indicates if a remote directory is open
52 
53  TFTP(): fHost(), fUser(), fPort(0), fParallel(0), fWindowSize(0),
54  fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
55  fRestartAt(0), fCurrentFile(), fSocket(0), fBytesWrite(0),
56  fBytesRead(0), fDir(kFALSE) { }
57  TFTP(const TFTP &); // not implemented
58  void operator=(const TFTP &); // idem
59  void Init(const char *url, Int_t parallel, Int_t wsize);
60  void PrintError(const char *where, Int_t err) const;
61  Int_t Recv(Int_t &status, EMessageTypes &kind) const;
62  void SetMode(Int_t mode) { fMode = mode; }
63 
64  static Long64_t fgBytesWrite; //number of bytes sent by all TFTP objects
65  static Long64_t fgBytesRead; //number of bytes received by all TFTP objects
66 
67 public:
68  enum {
69  kDfltBlockSize = 0x80000, // 512KB
70  kDfltWindowSize = 65535, // default tcp buffer size
71  kBinary = 0, // binary data transfer (default)
72  kAscii = 1 // ascii data transfer
73  };
74 
75  TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
76  TSocket *sock = 0);
77  virtual ~TFTP();
78 
79  void SetBlockSize(Int_t blockSize);
80  Int_t GetBlockSize() const { return fBlockSize; }
81  void SetRestartAt(Long64_t at) { fRestartAt = at; }
82  Long64_t GetRestartAt() const { return fRestartAt; }
83  Int_t GetMode() const { return fMode; }
84 
85  Bool_t IsOpen() const { return fSocket ? kTRUE : kFALSE; }
86  void Print(Option_t *opt = "") const;
87 
88  Long64_t PutFile(const char *file, const char *remoteName = 0);
89  Long64_t GetFile(const char *file, const char *localName = 0);
90 
91  Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists,
92  Bool_t print = kFALSE);
93  const char *GetDirEntry(Bool_t print = kFALSE);
94  Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
95  Int_t ChangeDirectory(const char *dir) const;
96  Int_t MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
97  Int_t DeleteDirectory(const char *dir) const;
98  Int_t ListDirectory(Option_t *cmd = "") const;
99  void FreeDirectory(Bool_t print = kFALSE);
100  Bool_t OpenDirectory(const char *name, Bool_t print = kFALSE);
101  Int_t PrintDirectory() const;
102  Int_t RenameFile(const char *file1, const char *file2) const;
103  Int_t DeleteFile(const char *file) const;
104  Int_t ChangePermission(const char *file, Int_t mode) const;
105  Int_t Close();
106  void Binary() { SetMode(kBinary); }
107  void Ascii() { SetMode(kAscii); }
108  TSocket *GetSocket() const { return fSocket; }
109 
110  // standard ftp equivalents...
111  void put(const char *file, const char *remoteName = 0) { PutFile(file, remoteName); }
112  void get(const char *file, const char *localName = 0) { GetFile(file, localName); }
113  void cd(const char *dir) const { ChangeDirectory(dir); }
114  void mkdir(const char *dir) const { MakeDirectory(dir); }
115  void rmdir(const char *dir) const { DeleteDirectory(dir); }
116  void ls(Option_t *cmd = "") const { ListDirectory(cmd); }
117  void pwd() const { PrintDirectory(); }
118  void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
119  void rm(const char *file) const { DeleteFile(file); }
120  void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
121  void bye() { Close(); }
122  void bin() { Binary(); }
123  void ascii() { Ascii(); }
124 
125  ClassDef(TFTP, 1) // File Transfer Protocol class using rootd
126 };
127 
128 #endif
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
Definition: TFTP.cxx:182
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
Definition: TFTP.cxx:1029
TString fUser
Definition: TFTP.h:38
TSocket * fSocket
Definition: TFTP.h:48
long long Long64_t
Definition: RtypesCore.h:69
Int_t fBlockSize
Definition: TFTP.h:44
const char Option_t
Definition: RtypesCore.h:62
void SetRestartAt(Long64_t at)
Definition: TFTP.h:81
void mv(const char *file1, const char *file2) const
Definition: TFTP.h:118
void operator=(const TFTP &)
void bye()
Definition: TFTP.h:121
Long64_t fBytesRead
Definition: TFTP.h:50
void Ascii()
Definition: TFTP.h:107
void rmdir(const char *dir) const
Definition: TFTP.h:115
void rm(const char *file) const
Definition: TFTP.h:119
Basic string class.
Definition: TString.h:129
Int_t DeleteFile(const char *file) const
Delete a remote file.
Definition: TFTP.cxx:821
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void ascii()
Definition: TFTP.h:123
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Definition: TFTP.cxx:914
Definition: TFTP.h:34
Int_t fLastBlock
Definition: TFTP.h:43
Long64_t GetRestartAt() const
Definition: TFTP.h:82
Long64_t GetFile(const char *file, const char *localName=0)
Transfer file from remote host.
Definition: TFTP.cxx:406
void bin()
Definition: TFTP.h:122
#define ClassDef(name, id)
Definition: Rtypes.h:297
Int_t fPort
Definition: TFTP.h:39
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
Definition: TFTP.cxx:628
Int_t GetBlockSize() const
Definition: TFTP.h:80
static Long64_t fgBytesWrite
Definition: TFTP.h:64
void cd(const char *dir) const
Definition: TFTP.h:113
void mkdir(const char *dir) const
Definition: TFTP.h:114
Long64_t fBytesWrite
connection to rootd
Definition: TFTP.h:49
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Definition: TFTP.cxx:149
Int_t fWindowSize
Definition: TFTP.h:41
void put(const char *file, const char *remoteName=0)
Definition: TFTP.h:111
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
Definition: TFTP.cxx:734
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
Definition: TFTP.cxx:853
static Long64_t fgBytesRead
Definition: TFTP.h:65
TString fCurrentFile
Definition: TFTP.h:47
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Definition: TFTP.cxx:191
void ls(Option_t *cmd="") const
The ls function lists the contents of a class on stdout.
Definition: TFTP.h:116
TString fHost
Definition: TFTP.h:37
Int_t fParallel
Definition: TFTP.h:40
EMessageTypes
Definition: MessageTypes.h:27
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
Definition: TFTP.cxx:988
Int_t fMode
Definition: TFTP.h:45
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
Definition: TFTP.cxx:790
Long64_t PutFile(const char *file, const char *remoteName=0)
Transfer file to remote host.
Definition: TFTP.cxx:233
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Definition: TFTP.cxx:667
void pwd() const
Definition: TFTP.h:117
const Bool_t kFALSE
Definition: RtypesCore.h:92
void Print(Option_t *opt="") const
Print some info about the FTP connection.
Definition: TFTP.cxx:157
Long64_t fRestartAt
Definition: TFTP.h:46
void chmod(const char *file, Int_t mode) const
Definition: TFTP.h:120
Int_t Close()
Close ftp connection.
Definition: TFTP.cxx:884
EAccessMode
Definition: TSystem.h:44
void SetBlockSize(Int_t blockSize)
Make sure the block size is a power of two, with a minimum of 32768.
Definition: TFTP.cxx:207
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t fProtocol
Definition: TFTP.h:42
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists, Bool_t print=kFALSE)
Returns kFALSE if one can access a file using the specified access mode.
Definition: TFTP.cxx:1111
void Binary()
Definition: TFTP.h:106
Bool_t fDir
Definition: TFTP.h:51
Definition: file.py:1
Int_t PrintDirectory() const
Print path of remote working directory.
Definition: TFTP.cxx:764
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
Definition: TFTP.cxx:95
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Definition: TFTP.cxx:956
void SetMode(Int_t mode)
Definition: TFTP.h:62
Int_t GetMode() const
Definition: TFTP.h:83
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
Definition: TFTP.cxx:702
const Bool_t kTRUE
Definition: RtypesCore.h:91
TFTP()
Definition: TFTP.h:53
Bool_t IsOpen() const
Definition: TFTP.h:85
TSocket * GetSocket() const
Definition: TFTP.h:108