32# include <sys/types.h>
47#if defined(R__UNIX) || defined(R__MACOSX)
81 "url must be of the form \"[root[up,s,k,g,h,ug]://]host[:port]\"");
98 if (
hurl.Contains(
"root")) {
104 url.GetUser(),
url.GetHost(),
url.GetPort()));
108 Error(
"TFTP",
"can't open %d-stream connection to rootd on "
109 "host %s at port %d", par,
url.GetHost(),
url.GetPort());
111 Error(
"TFTP",
"can't open connection to rootd on "
112 "host %s at port %d",
url.GetHost(),
url.GetPort());
116 fProtocol = fSocket->GetRemoteProtocol();
119 fHost =
url.GetHost();
120 fPort =
url.GetPort();
125 fBlockSize = kDfltBlockSize;
135 gROOT->GetListOfSockets()->Remove(fSocket);
136 gROOT->GetListOfSockets()->Add(
this);
161 Printf(
"Remote host: %s [%d]", fHost.Data(), fPort);
162 Printf(
"Remote user: %s", fUser.Data());
164 Printf(
"Security context: %s",
167 Printf(
"Rootd protocol vers.: %d", fSocket->GetRemoteProtocol());
169 Printf(
"Parallel sockets: %d", fParallel);
171 Printf(
"TCP window size: %d", fWindowSize);
172 Printf(
"Rootd protocol: %d", fProtocol);
173 Printf(
"Transfer block size: %d", fBlockSize);
174 Printf(
"Transfer mode: %s", fMode ?
"ascii" :
"binary");
175 Printf(
"Bytes sent: %lld", fBytesWrite);
176 Printf(
"Bytes received: %lld", fBytesRead);
196 if (!fSocket)
return -1;
209 if (blockSize < 32768) {
215 for (i = 0; i <
int(
sizeof(blockSize)*8); i++)
216 if ((blockSize >> i) == 1)
235 if (!IsOpen() || !file || !*file)
return -1;
237#if defined(R__WIN32) || defined(R__WINGCC)
239#elif defined(R__SEEK64)
245 Error(
"PutFile",
"cannot open %s in read mode", file);
253 Error(
"PutFile",
"%s not a regular file (%ld)", file, flags);
258 Warning(
"PutFile",
"could not stat %s", file);
272 if (fSocket->Send(
Form(
"%s %d %d %lld %lld",
remoteName, fBlockSize, fMode,
274 Error(
"PutFile",
"error sending kROOTD_PUTFILE command");
282 if (Recv(stat, kind) < 0 || kind ==
kROOTD_ERR) {
283 PrintError(
"PutFile", stat);
288 Info(
"PutFile",
"sending file %s (%lld bytes, starting at %lld)",
298 char *buf =
new char[fBlockSize];
299#if defined(R__SEEK64)
301#elif defined(R__WIN32)
310 if (left > fBlockSize)
313#if defined(R__SEEK64)
318 if (buf == (
char *) -1) {
319 Error(
"PutFile",
"mmap of file %s failed", file);
327 if (
siz < 0 ||
siz != left) {
328 Error(
"PutFile",
"error reading from file %s", file);
336 if (fSocket->SendRaw(buf+
skip, left-
skip) < 0) {
337 Error(
"PutFile",
"error sending buffer");
348 fBytesWrite += left-
skip;
349 fgBytesWrite += left-
skip;
370 if (Recv(stat, kind) < 0 || kind ==
kROOTD_ERR) {
371 PrintError(
"PutFile", stat);
383 Info(
"PutFile",
"%.3f seconds, %.2f Mbytes per second",
385 else if (
speed > 512)
386 Info(
"PutFile",
"%.3f seconds, %.2f Kbytes per second",
389 Info(
"PutFile",
"%.3f seconds, %.2f bytes per second",
408 if (!IsOpen() || !file || !*file)
return -1;
419 if (fSocket->Send(
Form(
"%s %d %d %lld", file, fBlockSize, fMode,
421 Error(
"GetFile",
"error sending kROOTD_GETFILE command");
428 if (Recv(stat, kind) < 0 || kind ==
kROOTD_ERR) {
429 PrintError(
"GetFile", stat);
439 Error(
"GetFile",
"error receiving remote file size");
455#if defined(R__WIN32) || defined(R__WINGCC)
456 if (fMode == kBinary)
462#elif defined(R__SEEK64)
468#if defined(R__WIN32) || defined(R__WINGCC)
469 if (fMode == kBinary)
473#elif defined(R__SEEK64)
498 Warning(
"GetFile",
"could not determine if there is enough free space to store file");
503#if defined(R__SEEK64)
505#elif defined(R__WIN32)
510 Error(
"GetFile",
"cannot seek to position %lld in file %s",
518 Info(
"GetFile",
"getting file %s (%lld bytes, starting at %lld)",
524 char *buf =
new char[fBlockSize];
527 buf2 =
new char[fBlockSize];
534 if (left > fBlockSize)
538 while ((
n = fSocket->RecvRaw(buf,
Int_t(left-
skip))) < 0 &&
543 Error(
"GetFile",
"error receiving buffer of length %d, got %d",
546 delete [] buf;
delete []
buf2;
552 if (fMode == kAscii) {
558 buf2[
j++] = buf[i++];
572 delete [] buf;
delete []
buf2;
577 Error(
"GetFile",
"error writing all requested bytes to file %s, wrote %ld of %d",
581 delete [] buf;
delete []
buf2;
585 fBytesRead += left-
skip;
586 fgBytesRead += left-
skip;
594 delete [] buf;
delete []
buf2;
611 Info(
"GetFile",
"%.3f seconds, %.2f Mbytes per second",
613 else if (
speed > 512)
614 Info(
"GetFile",
"%.3f seconds, %.2f Kbytes per second",
617 Info(
"GetFile",
"%.3f seconds, %.2f bytes per second",
630 if (!IsOpen())
return -1;
633 Error(
"ChangeDirectory",
"illegal directory name specified");
638 Error(
"ChangeDirectory",
"error sending kROOTD_CHDIR command");
646 Error(
"ChangeDirectory",
"error receiving chdir confirmation");
653 Error(
"ChangeDirectory",
"error receiving chdir confirmation");
658 Info(
"ChangeDirectory",
"%s",
mess);
669 if (!IsOpen())
return -1;
672 Error(
"MakeDirectory",
"illegal directory name specified");
677 Error(
"MakeDirectory",
"error sending kROOTD_MKDIR command");
685 Error(
"MakeDirectory",
"error receiving mkdir confirmation");
704 if (!IsOpen())
return -1;
707 Error(
"DeleteDirectory",
"illegal directory name specified");
712 Error(
"DeleteDirectory",
"error sending kROOTD_RMDIR command");
720 Error(
"DeleteDirectory",
"error receiving rmdir confirmation");
724 Info(
"DeleteDirectory",
"%s",
mess);
736 if (!IsOpen())
return -1;
742 Error(
"ListDirectory",
"error sending kROOTD_LSDIR command");
751 Error(
"ListDirectory",
"error receiving lsdir confirmation");
766 if (!IsOpen())
return -1;
769 Error(
"DeleteDirectory",
"error sending kROOTD_PWD command");
777 Error(
"PrintDirectory",
"error receiving pwd confirmation");
792 if (!IsOpen())
return -1;
795 Error(
"RenameFile",
"illegal file names specified");
800 Error(
"RenameFile",
"error sending kROOTD_MV command");
808 Error(
"RenameFile",
"error receiving mv confirmation");
823 if (!IsOpen())
return -1;
825 if (!file || !*file) {
826 Error(
"DeleteFile",
"illegal file name specified");
831 Error(
"DeleteFile",
"error sending kROOTD_RM command");
839 Error(
"DeleteFile",
"error receiving rm confirmation");
855 if (!IsOpen())
return -1;
857 if (!file || !*file) {
858 Error(
"ChangePermission",
"illegal file name specified");
863 Error(
"ChangePermission",
"error sending kROOTD_CHMOD command");
871 Error(
"ChangePermission",
"error receiving chmod confirmation");
875 Info(
"ChangePermission",
"%s",
mess);
886 if (!IsOpen())
return -1;
889 Error(
"Close",
"error sending kROOTD_CLOSE command");
900 gROOT->GetListOfSockets()->Remove(
this);
918 if (!IsOpen())
return fDir;
920 if (fProtocol < 12) {
921 Error(
"OpenDirectory",
"call not supported by remote rootd");
926 Error(
"OpenDirectory",
"illegal directory name specified");
931 Error(
"OpenDirectory",
"error sending kROOTD_OPENDIR command");
939 Error(
"OpenDirectory",
"error receiving opendir confirmation");
958 if (!IsOpen() || !fDir)
return;
960 if (fProtocol < 12) {
961 Error(
"FreeDirectory",
"call not supported by remote rootd");
966 Error(
"FreeDirectory",
"error sending kROOTD_FREEDIR command");
974 Error(
"FreeDirectory",
"error receiving freedir confirmation");
990 static char dirent[1024] = {0};
992 if (!IsOpen() || !fDir)
return 0;
994 if (fProtocol < 12) {
995 Error(
"GetDirEntry",
"call not supported by remote rootd");
1000 Error(
"GetDirEntry",
"error sending kROOTD_DIRENTRY command");
1008 Error(
"GetDirEntry",
"error receiving dir entry confirmation");
1017 return (
const char *)
dirent;
1033 if (!IsOpen())
return 1;
1035 if (fProtocol < 12) {
1036 Error(
"GetPathInfo",
"call not supported by remote rootd");
1040 if (!path || !*path) {
1041 Error(
"GetPathInfo",
"illegal path name specified");
1046 Error(
"GetPathInfo",
"error sending kROOTD_FSTAT command");
1054 Error(
"GetPathInfo",
"error receiving fstat confirmation");
1063 if (fProtocol > 12) {
1066 &uid, &gid, &
size, &mtime, &islink);
1069 &uid, &gid, &
size, &mtime, &islink);
1089 buf.
fDev = (
id >> 24);
1090 buf.
fIno = (
id & 0x00FFFFFF);
1113 if (!IsOpen())
return kTRUE;
1115 if (fProtocol < 12) {
1116 Error(
"AccessPathName",
"call not supported by remote rootd");
1120 if (!path || !*path) {
1121 Error(
"AccessPathName",
"illegal path name specified");
1126 Error(
"AccessPathName",
"error sending kROOTD_ACCESS command");
1134 Error(
"AccessPathName",
"error receiving access confirmation");
1138 Info(
"AccessPathName",
"%s",
mess);
R__EXTERN const char * gRootdErrStr[]
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
const char Option_t
Option string (const char)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD(mutex)
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
Int_t Close()
Close ftp connection.
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Int_t PrintDirectory() const
Print path of remote working directory.
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
void Print(Option_t *opt="") const override
Print some info about the FTP connection.
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
static Long64_t fgBytesWrite
Long64_t GetFile(const char *file, const char *localName=nullptr)
Transfer file from remote host.
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.
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Long64_t PutFile(const char *file, const char *remoteName=nullptr)
Transfer file to remote host.
TSocket * fSocket
! connection to rootd
static Long64_t fgBytesRead
void SetBlockSize(Int_t blockSize)
Make sure the block size is a power of two, with a minimum of 32768.
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
Int_t DeleteFile(const char *file) const
Delete a remote file.
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
This class implements client sockets.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: fs type, block size, number of blocks, number of free blocks.
static void ResetErrno()
Static function resetting system error number.
static Int_t GetErrno()
Static function returning system error number.
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
virtual const char * HostName()
Return the system's host name.
This class represents a WWW compatible URL.
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=nullptr, Int_t *err=nullptr)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
static Bool_t IsAuthenticated(const TSocket &s)
static TSecContext * GetSecContext(const TSocket &s)