ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TObject
26 #include "TObject.h"
27 #endif
28 #ifndef ROOT_TSystem
29 #include "TSystem.h"
30 #endif
31 #ifndef ROOT_TString
32 #include "TString.h"
33 #endif
34 #ifndef ROOT_MessageTypes
35 #include "MessageTypes.h"
36 #endif
37 
38 
39 class TSocket;
40 
41 
42 class TFTP : public TObject {
43 
44 private:
45  TString fHost; // FQDN of remote host
46  TString fUser; // remote user
47  Int_t fPort; // port to which to connect
48  Int_t fParallel; // number of parallel sockets
49  Int_t fWindowSize; // tcp window size used
50  Int_t fProtocol; // rootd protocol level
51  Int_t fLastBlock; // last block successfully transfered
52  Int_t fBlockSize; // size of data buffer used to transfer
53  Int_t fMode; // binary or ascii file transfer mode
54  Long64_t fRestartAt; // restart transmission at specified offset
55  TString fCurrentFile; // file currently being get or put
56  TSocket *fSocket; //! connection to rootd
57  Long64_t fBytesWrite; // number of bytes sent
58  Long64_t fBytesRead; // number of bytes received
59  Bool_t fDir; // Indicates if a remote directory is open
60 
61  TFTP(): fHost(), fUser(), fPort(0), fParallel(0), fWindowSize(0),
62  fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
64  fBytesRead(0), fDir(kFALSE) { }
65  TFTP(const TFTP &); // not implemented
66  void operator=(const TFTP &); // idem
67  void Init(const char *url, Int_t parallel, Int_t wsize);
68  void PrintError(const char *where, Int_t err) const;
69  Int_t Recv(Int_t &status, EMessageTypes &kind) const;
70  void SetMode(Int_t mode) { fMode = mode; }
71 
72  static Long64_t fgBytesWrite; //number of bytes sent by all TFTP objects
73  static Long64_t fgBytesRead; //number of bytes received by all TFTP objects
74 
75 public:
76  enum {
77  kDfltBlockSize = 0x80000, // 512KB
78  kDfltWindowSize = 65535, // default tcp buffer size
79  kBinary = 0, // binary data transfer (default)
80  kAscii = 1 // ascii data transfer
81  };
82 
83  TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
84  TSocket *sock = 0);
85  virtual ~TFTP();
86 
87  void SetBlockSize(Int_t blockSize);
88  Int_t GetBlockSize() const { return fBlockSize; }
90  Long64_t GetRestartAt() const { return fRestartAt; }
91  Int_t GetMode() const { return fMode; }
92 
93  Bool_t IsOpen() const { return fSocket ? kTRUE : kFALSE; }
94  void Print(Option_t *opt = "") const;
95 
96  Long64_t PutFile(const char *file, const char *remoteName = 0);
97  Long64_t GetFile(const char *file, const char *localName = 0);
98 
99  Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists,
100  Bool_t print = kFALSE);
101  const char *GetDirEntry(Bool_t print = kFALSE);
102  Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
103  Int_t ChangeDirectory(const char *dir) const;
104  Int_t MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
105  Int_t DeleteDirectory(const char *dir) const;
106  Int_t ListDirectory(Option_t *cmd = "") const;
107  void FreeDirectory(Bool_t print = kFALSE);
108  Bool_t OpenDirectory(const char *name, Bool_t print = kFALSE);
109  Int_t PrintDirectory() const;
110  Int_t RenameFile(const char *file1, const char *file2) const;
111  Int_t DeleteFile(const char *file) const;
112  Int_t ChangePermission(const char *file, Int_t mode) const;
113  Int_t Close();
114  void Binary() { SetMode(kBinary); }
115  void Ascii() { SetMode(kAscii); }
116  TSocket *GetSocket() const { return fSocket; }
117 
118  // standard ftp equivalents...
119  void put(const char *file, const char *remoteName = 0) { PutFile(file, remoteName); }
120  void get(const char *file, const char *localName = 0) { GetFile(file, localName); }
121  void cd(const char *dir) const { ChangeDirectory(dir); }
122  void mkdir(const char *dir) const { MakeDirectory(dir); }
123  void rmdir(const char *dir) const { DeleteDirectory(dir); }
124  void ls(Option_t *cmd = "") const { ListDirectory(cmd); }
125  void pwd() const { PrintDirectory(); }
126  void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
127  void rm(const char *file) const { DeleteFile(file); }
128  void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
129  void bye() { Close(); }
130  void bin() { Binary(); }
131  void ascii() { Ascii(); }
132 
133  ClassDef(TFTP, 1) // File Transfer Protocol class using rootd
134 };
135 
136 #endif
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
Definition: TFTP.cxx:182
void mkdir(const char *dir) const
Definition: TFTP.h:122
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:46
TSocket * fSocket
Definition: TFTP.h:56
long long Long64_t
Definition: RtypesCore.h:69
Int_t fBlockSize
Definition: TFTP.h:52
const char Option_t
Definition: RtypesCore.h:62
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
Definition: TFTP.cxx:853
void SetRestartAt(Long64_t at)
Definition: TFTP.h:89
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
Definition: TFTP.cxx:790
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Definition: TFTP.cxx:667
void operator=(const TFTP &)
void bye()
Definition: TFTP.h:129
Long64_t fBytesRead
Definition: TFTP.h:58
void Ascii()
Definition: TFTP.h:115
Basic string class.
Definition: TString.h:137
Int_t PrintDirectory() const
Print path of remote working directory.
Definition: TFTP.cxx:764
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void ascii()
Definition: TFTP.h:131
const Bool_t kFALSE
Definition: Rtypes.h:92
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Definition: TFTP.cxx:914
Definition: TFTP.h:42
TObject Int_t at
Int_t fLastBlock
Definition: TFTP.h:51
void cd(const char *dir) const
Definition: TFTP.h:121
Long64_t GetFile(const char *file, const char *localName=0)
Transfer file from remote host.
Definition: TFTP.cxx:406
void bin()
Definition: TFTP.h:130
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t fPort
Definition: TFTP.h:47
void Print(Option_t *opt="") const
Print some info about the FTP connection.
Definition: TFTP.cxx:157
static Long64_t fgBytesWrite
Definition: TFTP.h:72
void rm(const char *file) const
Definition: TFTP.h:127
Long64_t fBytesWrite
connection to rootd
Definition: TFTP.h:57
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Definition: TFTP.cxx:149
Int_t fWindowSize
Definition: TFTP.h:49
Int_t DeleteFile(const char *file) const
Delete a remote file.
Definition: TFTP.cxx:821
void put(const char *file, const char *remoteName=0)
Definition: TFTP.h:119
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
Definition: TFTP.cxx:734
Int_t GetBlockSize() const
Definition: TFTP.h:88
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
Definition: TFTP.cxx:702
static Long64_t fgBytesRead
Definition: TFTP.h:73
TString fCurrentFile
Definition: TFTP.h:55
Long64_t GetRestartAt() const
Definition: TFTP.h:90
TSocket * GetSocket() const
Definition: TFTP.h:116
TString fHost
Definition: TFTP.h:45
Int_t fParallel
Definition: TFTP.h:48
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:53
void ls(Option_t *cmd="") const
The ls function lists the contents of a class on stdout.
Definition: TFTP.h:124
Long64_t PutFile(const char *file, const char *remoteName=0)
Transfer file to remote host.
Definition: TFTP.cxx:233
Int_t GetMode() const
Definition: TFTP.h:91
tuple file
Definition: fildir.py:20
Long64_t fRestartAt
Definition: TFTP.h:54
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
Definition: TFTP.cxx:628
void dir(char *path=0)
Definition: rootalias.C:30
void pwd() const
Definition: TFTP.h:125
Int_t Close()
Close ftp connection.
Definition: TFTP.cxx:884
EAccessMode
Definition: TSystem.h:54
void mv(const char *file1, const char *file2) const
Definition: TFTP.h:126
#define name(a, b)
Definition: linkTestLib0.cpp:5
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:58
Int_t fProtocol
Definition: TFTP.h:50
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 chmod(const char *file, Int_t mode) const
Definition: TFTP.h:128
void Binary()
Definition: TFTP.h:114
Bool_t fDir
Definition: TFTP.h:59
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
Definition: TFTP.cxx:95
void rmdir(const char *dir) const
Definition: TFTP.h:123
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Definition: TFTP.cxx:956
Bool_t IsOpen() const
Definition: TFTP.h:93
void SetMode(Int_t mode)
Definition: TFTP.h:70
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Definition: TFTP.cxx:191
const Bool_t kTRUE
Definition: Rtypes.h:91
TFTP()
Definition: TFTP.h:61