32# include <sys/types.h>
46#if defined(R__UNIX) || defined(R__MACOSX)
78 if (
s.Contains(
"://")) {
79 if (!
s.BeginsWith(
"root")) {
81 "url must be of the form \"[root[up,s,k,g,h,ug]://]host[:port]\"");
108 Error(
"TFTP",
"can't open %d-stream connection to rootd on "
111 Error(
"TFTP",
"can't open connection to rootd on "
136 gROOT->GetListOfSockets()->Add(
this);
164 Printf(
"Security context: %s",
173 Printf(
"Transfer mode: %s",
fMode ?
"ascii" :
"binary");
208 if (blockSize < 32768) {
214 for (i = 0; i <
int(
sizeof(blockSize)*8); i++)
215 if ((blockSize >> i) == 1)
236#if defined(R__WIN32) || defined(R__WINGCC)
238#elif defined(R__SEEK64)
244 Error(
"PutFile",
"cannot open %s in read mode",
file);
252 Error(
"PutFile",
"%s not a regular file (%ld)",
file, flags);
268 if (restartat && (restartat >= size))
273 Error(
"PutFile",
"error sending kROOTD_PUTFILE command");
287 Info(
"PutFile",
"sending file %s (%lld bytes, starting at %lld)",
288 file, size, restartat);
294 Int_t skip = restartat - pos;
298#if defined(R__SEEK64)
299 lseek64(fd, pos, SEEK_SET);
300#elif defined(R__WIN32)
301 _lseeki64(fd, pos, SEEK_SET);
303 lseek(fd, pos, SEEK_SET);
312#if defined(R__SEEK64)
313 char *buf = (
char*) mmap64(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos);
315 char *buf = (
char*) mmap(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos);
317 if (buf == (
char *) -1) {
318 Error(
"PutFile",
"mmap of file %s failed",
file);
326 if (siz < 0 || siz != left) {
327 Error(
"PutFile",
"error reading from file %s",
file);
336 Error(
"PutFile",
"error sending buffer");
378 speed =
Double_t(size - restartat) / t;
382 Info(
"PutFile",
"%.3f seconds, %.2f Mbytes per second",
384 else if (speed > 512)
385 Info(
"PutFile",
"%.3f seconds, %.2f Kbytes per second",
388 Info(
"PutFile",
"%.3f seconds, %.2f bytes per second",
420 Error(
"GetFile",
"error sending kROOTD_GETFILE command");
438 Error(
"GetFile",
"error receiving remote file size");
442 sscanf(mess,
"%I64d", &size);
444 sscanf(mess,
"%lld", &size);
448 if (restartat && (restartat >= size))
454#if defined(R__WIN32) || defined(R__WINGCC)
456 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY |
O_BINARY,
459 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY,
461#elif defined(R__SEEK64)
462 fd = open64(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600);
464 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600);
467#if defined(R__WIN32) || defined(R__WINGCC)
469 fd =
open(localName, O_WRONLY |
O_BINARY, S_IREAD | S_IWRITE);
471 fd =
open(localName, O_WRONLY, S_IREAD | S_IWRITE);
472#elif defined(R__SEEK64)
473 fd = open64(localName, O_WRONLY, 0600);
475 fd =
open(localName, O_WRONLY, 0600);
480 Error(
"GetFile",
"cannot open %s", localName);
486 if (strcmp(localName,
"/dev/null")) {
490 if (space < size - restartat) {
491 Error(
"GetFile",
"not enough space to store file %s", localName);
497 Warning(
"GetFile",
"could not determine if there is enough free space to store file");
502#if defined(R__SEEK64)
503 if (lseek64(fd, restartat, SEEK_SET) < 0) {
504#elif defined(R__WIN32)
505 if (_lseeki64(fd, restartat, SEEK_SET) < 0) {
507 if (lseek(fd, restartat, SEEK_SET) < 0) {
509 Error(
"GetFile",
"cannot seek to position %lld in file %s",
510 restartat, localName);
517 Info(
"GetFile",
"getting file %s (%lld bytes, starting at %lld)",
518 localName, size, restartat);
529 Int_t skip = restartat - pos;
541 if (
n !=
Int_t(left-skip)) {
542 Error(
"GetFile",
"error receiving buffer of length %d, got %d",
545 delete [] buf;
delete [] buf2;
557 buf2[j++] = buf[i++];
568 SysError(
"GetFile",
"error writing file %s", localName);
571 delete [] buf;
delete [] buf2;
576 Error(
"GetFile",
"error writing all requested bytes to file %s, wrote %ld of %d",
580 delete [] buf;
delete [] buf2;
593 delete [] buf;
delete [] buf2;
606 speed =
Double_t(size - restartat) / t;
610 Info(
"GetFile",
"%.3f seconds, %.2f Mbytes per second",
612 else if (speed > 512)
613 Info(
"GetFile",
"%.3f seconds, %.2f Kbytes per second",
616 Info(
"GetFile",
"%.3f seconds, %.2f bytes per second",
632 Error(
"ChangeDirectory",
"illegal directory name specified");
637 Error(
"ChangeDirectory",
"error sending kROOTD_CHDIR command");
645 Error(
"ChangeDirectory",
"error receiving chdir confirmation");
652 Error(
"ChangeDirectory",
"error receiving chdir confirmation");
657 Info(
"ChangeDirectory",
"%s", mess);
671 Error(
"MakeDirectory",
"illegal directory name specified");
676 Error(
"MakeDirectory",
"error sending kROOTD_MKDIR command");
684 Error(
"MakeDirectory",
"error receiving mkdir confirmation");
689 Info(
"MakeDirectory",
"%s", mess);
691 if (!strncmp(mess,
"OK:",3))
706 Error(
"DeleteDirectory",
"illegal directory name specified");
711 Error(
"DeleteDirectory",
"error sending kROOTD_RMDIR command");
719 Error(
"DeleteDirectory",
"error receiving rmdir confirmation");
723 Info(
"DeleteDirectory",
"%s", mess);
741 Error(
"ListDirectory",
"error sending kROOTD_LSDIR command");
750 Error(
"ListDirectory",
"error receiving lsdir confirmation");
768 Error(
"DeleteDirectory",
"error sending kROOTD_PWD command");
776 Error(
"PrintDirectory",
"error receiving pwd confirmation");
780 Info(
"PrintDirectory",
"%s", mess);
793 if (!file1 || !file2 || !*file1 || !*file2) {
794 Error(
"RenameFile",
"illegal file names specified");
799 Error(
"RenameFile",
"error sending kROOTD_MV command");
807 Error(
"RenameFile",
"error receiving mv confirmation");
811 Info(
"RenameFile",
"%s", mess);
825 Error(
"DeleteFile",
"illegal file name specified");
830 Error(
"DeleteFile",
"error sending kROOTD_RM command");
838 Error(
"DeleteFile",
"error receiving rm confirmation");
842 Info(
"DeleteFile",
"%s", mess);
857 Error(
"ChangePermission",
"illegal file name specified");
862 Error(
"ChangePermission",
"error sending kROOTD_CHMOD command");
870 Error(
"ChangePermission",
"error receiving chmod confirmation");
874 Info(
"ChangePermission",
"%s", mess);
888 Error(
"Close",
"error sending kROOTD_CLOSE command");
899 gROOT->GetListOfSockets()->Remove(
this);
920 Error(
"OpenDirectory",
"call not supported by remote rootd");
925 Error(
"OpenDirectory",
"illegal directory name specified");
930 Error(
"OpenDirectory",
"error sending kROOTD_OPENDIR command");
938 Error(
"OpenDirectory",
"error receiving opendir confirmation");
943 Info(
"OpenDirectory",
"%s", mess);
945 if (!strncmp(mess,
"OK:",3)) {
960 Error(
"FreeDirectory",
"call not supported by remote rootd");
965 Error(
"FreeDirectory",
"error sending kROOTD_FREEDIR command");
973 Error(
"FreeDirectory",
"error receiving freedir confirmation");
978 Info(
"FreeDirectory",
"%s", mess);
989 static char dirent[1024] = {0};
994 Error(
"GetDirEntry",
"call not supported by remote rootd");
999 Error(
"GetDirEntry",
"error sending kROOTD_DIRENTRY command");
1007 Error(
"GetDirEntry",
"error receiving dir entry confirmation");
1012 Info(
"GetDirEntry",
"%s", mess);
1014 if (!strncmp(mess,
"OK:",3)) {
1015 strlcpy(dirent,mess+3,
sizeof(dirent));
1016 return (
const char *)dirent;
1035 Error(
"GetPathInfo",
"call not supported by remote rootd");
1039 if (!path || !*path) {
1040 Error(
"GetPathInfo",
"illegal path name specified");
1045 Error(
"GetPathInfo",
"error sending kROOTD_FSTAT command");
1053 Error(
"GetPathInfo",
"error receiving fstat confirmation");
1057 Info(
"GetPathInfo",
"%s", mess);
1059 Int_t mode, uid, gid, islink;
1064 sscanf(mess,
"%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode,
1065 &uid, &gid, &size, &mtime, &islink);
1067 sscanf(mess,
"%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode,
1068 &uid, &gid, &size, &mtime, &islink);
1082 sscanf(mess,
"%ld %I64d %ld %ld", &
id, &size, &flags, &mtime);
1084 sscanf(mess,
"%ld %lld %ld %ld", &
id, &size, &flags, &mtime);
1088 buf.
fDev = (
id >> 24);
1089 buf.
fIno = (
id & 0x00FFFFFF);
1115 Error(
"AccessPathName",
"call not supported by remote rootd");
1119 if (!path || !*path) {
1120 Error(
"AccessPathName",
"illegal path name specified");
1125 Error(
"AccessPathName",
"error sending kROOTD_ACCESS command");
1133 Error(
"AccessPathName",
"error receiving access confirmation");
1137 Info(
"AccessPathName",
"%s", mess);
1139 if (!strncmp(mess,
"OK",2))
R__EXTERN const char * gRootdErrStr[]
R__EXTERN TVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
void Printf(const char *fmt,...)
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD(mutex)
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
Long64_t PutFile(const char *file, const char *remoteName=0)
Transfer file to remote host.
Int_t DeleteFile(const char *file) const
Delete a remote file.
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
void Init(const char *url, Int_t parallel, Int_t wsize)
Set up the actual connection.
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
static Long64_t fgBytesRead
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Int_t PrintDirectory() const
Print path of remote working directory.
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
Long64_t GetFile(const char *file, const char *localName=0)
Transfer file from remote host.
void SetBlockSize(Int_t blockSize)
Make sure the block size is a power of two, with a minimum of 32768.
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
Int_t Close()
Close ftp connection.
void Print(Option_t *opt="") const
Print some info about the FTP connection.
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 ChangeDirectory(const char *dir) const
Change the remote directory.
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
Long64_t fBytesWrite
connection to rootd
static Long64_t fgBytesWrite
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
const char * GetUser() const
virtual const char * AsString(TString &out)
Returns short string with relevant information about this security context.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Int_t GetRemoteProtocol() const
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
TSecContext * GetSecContext() const
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=0, Int_t *err=0)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
virtual Bool_t IsAuthenticated() const
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
TString & Insert(Ssiz_t pos, const char *s)
const char * Data() 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.
const char * GetUser() const
const char * GetHost() const
const char * GetProtocol() const
static constexpr double s