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
33namespace ROOT::Deprecated {
34
35class TFTP : public TObject {
36
37private:
38 TString fHost; // FQDN of remote host
39 TString fUser; // remote user
40 Int_t fPort; // port to which to connect
41 Int_t fParallel; // number of parallel sockets
42 Int_t fWindowSize; // tcp window size used
43 Int_t fProtocol; // rootd protocol level
44 Int_t fLastBlock; // last block successfully transferred
45 Int_t fBlockSize; // size of data buffer used to transfer
46 Int_t fMode; // binary or ascii file transfer mode
47 Long64_t fRestartAt; // restart transmission at specified offset
48 TString fCurrentFile; // file currently being get or put
49 TSocket *fSocket; ///<! connection to rootd
50 Long64_t fBytesWrite; // number of bytes sent
51 Long64_t fBytesRead; // number of bytes received
52 Bool_t fDir; // Indicates if a remote directory is open
53
55 fProtocol(0), fLastBlock(0), fBlockSize(0), fMode(0),
56 fRestartAt(0), fCurrentFile(), fSocket(nullptr), fBytesWrite(0),
57 fBytesRead(0), fDir(kFALSE) { }
58 TFTP(const TFTP &) = delete;
59 void operator=(const TFTP &) = delete;
60 void Init(const char *url, Int_t parallel, Int_t wsize);
61 void PrintError(const char *where, Int_t err) const;
62 Int_t Recv(Int_t &status, EMessageTypes &kind) const;
64
65 static Long64_t fgBytesWrite; //number of bytes sent by all TFTP objects
66 static Long64_t fgBytesRead; //number of bytes received by all TFTP objects
67
68public:
69 enum {
70 kDfltBlockSize = 0x80000, // 512KB
71 kDfltWindowSize = 65535, // default tcp buffer size
72 kBinary = 0, // binary data transfer (default)
73 kAscii = 1 // ascii data transfer
74 };
75
76 TFTP(const char *url, Int_t parallel = 1, Int_t wsize = kDfltWindowSize,
77 TSocket *sock = nullptr);
78 virtual ~TFTP();
79
80 void SetBlockSize(Int_t blockSize);
81 Int_t GetBlockSize() const { return fBlockSize; }
82 void SetRestartAt(Long64_t at) { fRestartAt = at; }
83 Long64_t GetRestartAt() const { return fRestartAt; }
84 Int_t GetMode() const { return fMode; }
85
86 Bool_t IsOpen() const { return fSocket ? kTRUE : kFALSE; }
87 void Print(Option_t *opt = "") const override;
88
89 Long64_t PutFile(const char *file, const char *remoteName = nullptr);
90 Long64_t GetFile(const char *file, const char *localName = nullptr);
91
93 Bool_t print = kFALSE);
94 const char *GetDirEntry(Bool_t print = kFALSE);
95 Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print = kFALSE);
96 Int_t ChangeDirectory(const char *dir) const;
97 Int_t MakeDirectory(const char *dir, Bool_t print = kFALSE) const;
98 Int_t DeleteDirectory(const char *dir) const;
99 Int_t ListDirectory(Option_t *cmd = "") const;
100 void FreeDirectory(Bool_t print = kFALSE);
101 Bool_t OpenDirectory(const char *name, Bool_t print = kFALSE);
102 Int_t PrintDirectory() const;
103 Int_t RenameFile(const char *file1, const char *file2) const;
104 Int_t DeleteFile(const char *file) const;
105 Int_t ChangePermission(const char *file, Int_t mode) const;
106 Int_t Close();
107 void Binary() { SetMode(kBinary); }
108 void Ascii() { SetMode(kAscii); }
109 TSocket *GetSocket() const { return fSocket; }
110
111 // standard ftp equivalents...
112 void put(const char *file, const char *remoteName = nullptr) { PutFile(file, remoteName); }
113 void get(const char *file, const char *localName = nullptr) { GetFile(file, localName); }
114 void cd(const char *dir) const { ChangeDirectory(dir); }
115 void mkdir(const char *dir) const { MakeDirectory(dir); }
116 void rmdir(const char *dir) const { DeleteDirectory(dir); }
117 void ls(Option_t *cmd = "") const override { ListDirectory(cmd); }
118 void pwd() const { PrintDirectory(); }
119 void mv(const char *file1, const char *file2) const { RenameFile(file1, file2); }
120 void rm(const char *file) const { DeleteFile(file); }
121 void chmod(const char *file, Int_t mode) const { ChangePermission(file, mode); }
122 void bye() { Close(); }
123 void bin() { Binary(); }
124 void ascii() { Ascii(); }
125
126 ClassDefOverride(TFTP, 1) // File Transfer Protocol class using rootd
127};
128
129} // namespace ROOT::Deprecated
130
131using TFTP R__DEPRECATED(6, 42, "TFTP is deprecated") = ROOT::Deprecated::TFTP;
132
133#endif
EMessageTypes
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:510
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:145
EAccessMode
Definition TSystem.h:51
@ kFileExists
Definition TSystem.h:52
TFTP(const TFTP &)=delete
void cd(const char *dir) const
Definition TFTP.h:114
Int_t GetBlockSize() const
Definition TFTP.h:81
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
Definition TFTP.cxx:628
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
Definition TFTP.cxx:853
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
Definition TFTP.cxx:702
Long64_t fBytesWrite
Definition TFTP.h:50
void put(const char *file, const char *remoteName=nullptr)
Definition TFTP.h:112
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
TSocket * GetSocket() const
Definition TFTP.h:109
void rm(const char *file) const
Definition TFTP.h:120
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Definition TFTP.cxx:667
void mkdir(const char *dir) const
Definition TFTP.h:115
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Definition TFTP.cxx:956
void operator=(const TFTP &)=delete
TString fCurrentFile
Definition TFTP.h:48
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
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
Definition TFTP.cxx:182
void rmdir(const char *dir) const
Definition TFTP.h:116
void ls(Option_t *cmd="") const override
The ls function lists the contents of a class on stdout.
Definition TFTP.h:117
void get(const char *file, const char *localName=nullptr)
Definition TFTP.h:113
void Print(Option_t *opt="") const override
Print some info about the FTP connection.
Definition TFTP.cxx:156
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
Definition TFTP.cxx:790
static Long64_t fgBytesWrite
Definition TFTP.h:65
Long64_t GetFile(const char *file, const char *localName=nullptr)
Transfer file from remote host.
Definition TFTP.cxx:406
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 pwd() const
Definition TFTP.h:118
Long64_t GetRestartAt() const
Definition TFTP.h:83
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Definition TFTP.cxx:191
Bool_t IsOpen() const
Definition TFTP.h:86
void mv(const char *file1, const char *file2) const
Definition TFTP.h:119
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Definition TFTP.cxx:914
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Definition TFTP.cxx:148
Long64_t PutFile(const char *file, const char *remoteName=nullptr)
Transfer file to remote host.
Definition TFTP.cxx:233
TSocket * fSocket
! connection to rootd
Definition TFTP.h:49
Int_t GetMode() const
Definition TFTP.h:84
Long64_t fRestartAt
Definition TFTP.h:47
static Long64_t fgBytesRead
Definition TFTP.h:66
Long64_t fBytesRead
Definition TFTP.h:51
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 SetRestartAt(Long64_t at)
Definition TFTP.h:82
void SetMode(Int_t mode)
Definition TFTP.h:63
void chmod(const char *file, Int_t mode) const
Definition TFTP.h:121
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
Definition TFTP.cxx:94
Int_t DeleteFile(const char *file) const
Delete a remote file.
Definition TFTP.cxx:821
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
Definition TFTP.cxx:1029
Mother of all ROOT objects.
Definition TObject.h:42
This class implements client sockets.
Definition TSocket.h:54
Basic string class.
Definition TString.h:138