Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
31class TSocket;
32
33
34class TFTP : public TObject {
35
36private:
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
54 fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(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
67public:
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
EMessageTypes
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
char name[80]
Definition TGX11.cxx:110
EAccessMode
Definition TSystem.h:43
@ kFileExists
Definition TSystem.h:44
Definition TFTP.h:34
Int_t fLastBlock
Definition TFTP.h:43
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Definition TFTP.cxx:667
Int_t fParallel
Definition TFTP.h:40
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
Definition TFTP.cxx:702
Int_t GetMode() const
Definition TFTP.h:83
Long64_t PutFile(const char *file, const char *remoteName=0)
Transfer file to remote host.
Definition TFTP.cxx:233
void ascii()
Definition TFTP.h:123
TString fUser
Definition TFTP.h:38
Int_t DeleteFile(const char *file) const
Delete a remote file.
Definition TFTP.cxx:821
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
Definition TFTP.cxx:182
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Definition TFTP.cxx:191
void pwd() const
Definition TFTP.h:117
void mkdir(const char *dir) const
Definition TFTP.h:114
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
Definition TFTP.cxx:95
void bye()
Definition TFTP.h:121
void SetRestartAt(Long64_t at)
Definition TFTP.h:81
void Binary()
Definition TFTP.h:106
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Definition TFTP.cxx:956
void Ascii()
Definition TFTP.h:107
void operator=(const TFTP &)
Int_t fMode
Definition TFTP.h:45
Int_t fBlockSize
Definition TFTP.h:44
@ kDfltBlockSize
Definition TFTP.h:69
@ kBinary
Definition TFTP.h:71
@ kAscii
Definition TFTP.h:72
@ kDfltWindowSize
Definition TFTP.h:70
TString fCurrentFile
Definition TFTP.h:47
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
Definition TFTP.cxx:1029
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
Definition TFTP.cxx:790
void chmod(const char *file, Int_t mode) const
Definition TFTP.h:120
TSocket * fSocket
Definition TFTP.h:48
Long64_t fBytesRead
Definition TFTP.h:50
static Long64_t fgBytesRead
Definition TFTP.h:65
void SetMode(Int_t mode)
Definition TFTP.h:62
void mv(const char *file1, const char *file2) const
Definition TFTP.h:118
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Definition TFTP.cxx:914
Int_t PrintDirectory() const
Print path of remote working directory.
Definition TFTP.cxx:764
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
Definition TFTP.cxx:734
Long64_t GetFile(const char *file, const char *localName=0)
Transfer file from remote host.
Definition TFTP.cxx:406
void get(const char *file, const char *localName=0)
Definition TFTP.h:112
TFTP(const TFTP &)
void bin()
Definition TFTP.h:122
void SetBlockSize(Int_t blockSize)
Make sure the block size is a power of two, with a minimum of 32768.
Definition TFTP.cxx:207
void rm(const char *file) const
Definition TFTP.h:119
TSocket * GetSocket() const
Definition TFTP.h:108
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
Definition TFTP.cxx:853
TString fHost
Definition TFTP.h:37
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
Definition TFTP.cxx:988
Int_t Close()
Close ftp connection.
Definition TFTP.cxx:884
void Print(Option_t *opt="") const
Print some info about the FTP connection.
Definition TFTP.cxx:157
void rmdir(const char *dir) const
Definition TFTP.h:115
Long64_t GetRestartAt() const
Definition TFTP.h:82
Long64_t fRestartAt
Definition TFTP.h:46
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
Bool_t IsOpen() const
Definition TFTP.h:85
void cd(const char *dir) const
Definition TFTP.h:113
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
Definition TFTP.cxx:628
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Definition TFTP.cxx:149
TFTP()
Definition TFTP.h:53
Long64_t fBytesWrite
connection to rootd
Definition TFTP.h:49
void put(const char *file, const char *remoteName=0)
Definition TFTP.h:111
Int_t fWindowSize
Definition TFTP.h:41
void ls(Option_t *cmd="") const
The ls function lists the contents of a class on stdout.
Definition TFTP.h:116
Bool_t fDir
Definition TFTP.h:51
static Long64_t fgBytesWrite
Definition TFTP.h:64
Int_t GetBlockSize() const
Definition TFTP.h:80
Int_t fPort
Definition TFTP.h:39
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:136
Definition file.py:1