Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 #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