32# include <sys/types.h>
47#if defined(R__UNIX) || defined(R__MACOSX)
79 if (
s.Contains(
"://")) {
80 if (!
s.BeginsWith(
"root")) {
82 "url must be of the form \"[root[up,s,k,g,h,ug]://]host[:port]\"");
109 Error(
"TFTP",
"can't open %d-stream connection to rootd on "
112 Error(
"TFTP",
"can't open connection to rootd on "
137 gROOT->GetListOfSockets()->Add(
this);
165 Printf(
"Security context: %s",
174 Printf(
"Transfer mode: %s",
fMode ?
"ascii" :
"binary");
209 if (blockSize < 32768) {
215 for (i = 0; i < int(
sizeof(blockSize)*8); i++)
216 if ((blockSize >> i) == 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);
269 if (restartat && (restartat >= size))
274 Error(
"PutFile",
"error sending kROOTD_PUTFILE command");
288 Info(
"PutFile",
"sending file %s (%lld bytes, starting at %lld)",
289 file, size, restartat);
295 Int_t skip = restartat - pos;
299#if defined(R__SEEK64)
300 lseek64(fd, pos, SEEK_SET);
301#elif defined(R__WIN32)
302 _lseeki64(fd, pos, SEEK_SET);
304 lseek(fd, pos, SEEK_SET);
313#if defined(R__SEEK64)
314 char *buf = (
char*) mmap64(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos);
316 char *buf = (
char*) mmap(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos);
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);
337 Error(
"PutFile",
"error sending buffer");
379 speed =
Double_t(size - restartat) / t;
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",
421 Error(
"GetFile",
"error sending kROOTD_GETFILE command");
439 Error(
"GetFile",
"error receiving remote file size");
443 sscanf(mess,
"%I64d", &size);
445 sscanf(mess,
"%lld", &size);
449 if (restartat && (restartat >= size))
455#if defined(R__WIN32) || defined(R__WINGCC)
457 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY |
O_BINARY,
460 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY,
462#elif defined(R__SEEK64)
463 fd = open64(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600);
465 fd =
open(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600);
468#if defined(R__WIN32) || defined(R__WINGCC)
470 fd =
open(localName, O_WRONLY |
O_BINARY, S_IREAD | S_IWRITE);
472 fd =
open(localName, O_WRONLY, S_IREAD | S_IWRITE);
473#elif defined(R__SEEK64)
474 fd = open64(localName, O_WRONLY, 0600);
476 fd =
open(localName, O_WRONLY, 0600);
481 Error(
"GetFile",
"cannot open %s", localName);
487 if (strcmp(localName,
"/dev/null")) {
491 if (space < size - restartat) {
492 Error(
"GetFile",
"not enough space to store file %s", localName);
498 Warning(
"GetFile",
"could not determine if there is enough free space to store file");
503#if defined(R__SEEK64)
504 if (lseek64(fd, restartat, SEEK_SET) < 0) {
505#elif defined(R__WIN32)
506 if (_lseeki64(fd, restartat, SEEK_SET) < 0) {
508 if (lseek(fd, restartat, SEEK_SET) < 0) {
510 Error(
"GetFile",
"cannot seek to position %lld in file %s",
511 restartat, localName);
518 Info(
"GetFile",
"getting file %s (%lld bytes, starting at %lld)",
519 localName, size, restartat);
530 Int_t skip = restartat - pos;
542 if (
n !=
Int_t(left-skip)) {
543 Error(
"GetFile",
"error receiving buffer of length %d, got %d",
546 delete [] buf;
delete [] buf2;
558 buf2[j++] = buf[i++];
569 SysError(
"GetFile",
"error writing file %s", localName);
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;
594 delete [] buf;
delete [] buf2;
607 speed =
Double_t(size - restartat) / t;
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",
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);
672 Error(
"MakeDirectory",
"illegal directory name specified");
677 Error(
"MakeDirectory",
"error sending kROOTD_MKDIR command");
685 Error(
"MakeDirectory",
"error receiving mkdir confirmation");
690 Info(
"MakeDirectory",
"%s", mess);
692 if (!strncmp(mess,
"OK:",3))
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);
742 Error(
"ListDirectory",
"error sending kROOTD_LSDIR command");
751 Error(
"ListDirectory",
"error receiving lsdir confirmation");
769 Error(
"DeleteDirectory",
"error sending kROOTD_PWD command");
777 Error(
"PrintDirectory",
"error receiving pwd confirmation");
781 Info(
"PrintDirectory",
"%s", mess);
794 if (!file1 || !file2 || !*file1 || !*file2) {
795 Error(
"RenameFile",
"illegal file names specified");
800 Error(
"RenameFile",
"error sending kROOTD_MV command");
808 Error(
"RenameFile",
"error receiving mv confirmation");
812 Info(
"RenameFile",
"%s", mess);
826 Error(
"DeleteFile",
"illegal file name specified");
831 Error(
"DeleteFile",
"error sending kROOTD_RM command");
839 Error(
"DeleteFile",
"error receiving rm confirmation");
843 Info(
"DeleteFile",
"%s", mess);
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);
889 Error(
"Close",
"error sending kROOTD_CLOSE command");
900 gROOT->GetListOfSockets()->Remove(
this);
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");
944 Info(
"OpenDirectory",
"%s", mess);
946 if (!strncmp(mess,
"OK:",3)) {
961 Error(
"FreeDirectory",
"call not supported by remote rootd");
966 Error(
"FreeDirectory",
"error sending kROOTD_FREEDIR command");
974 Error(
"FreeDirectory",
"error receiving freedir confirmation");
979 Info(
"FreeDirectory",
"%s", mess);
990 static char dirent[1024] = {0};
995 Error(
"GetDirEntry",
"call not supported by remote rootd");
1000 Error(
"GetDirEntry",
"error sending kROOTD_DIRENTRY command");
1007 if (
fSocket->
Recv(mess,
sizeof(mess), what) < 0) {
1008 Error(
"GetDirEntry",
"error receiving dir entry confirmation");
1013 Info(
"GetDirEntry",
"%s", mess);
1015 if (!strncmp(mess,
"OK:",3)) {
1016 strlcpy(dirent,mess+3,
sizeof(dirent));
1017 return (
const char *)dirent;
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");
1053 if (
fSocket->
Recv(mess,
sizeof(mess), what) < 0) {
1054 Error(
"GetPathInfo",
"error receiving fstat confirmation");
1058 Info(
"GetPathInfo",
"%s", mess);
1060 Int_t mode, uid, gid, islink;
1065 sscanf(mess,
"%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode,
1066 &uid, &gid, &size, &mtime, &islink);
1068 sscanf(mess,
"%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode,
1069 &uid, &gid, &size, &mtime, &islink);
1083 sscanf(mess,
"%ld %I64d %ld %ld", &
id, &size, &flags, &mtime);
1085 sscanf(mess,
"%ld %lld %ld %ld", &
id, &size, &flags, &mtime);
1089 buf.
fDev = (
id >> 24);
1090 buf.
fIno = (
id & 0x00FFFFFF);
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");
1133 if (
fSocket->
Recv(mess,
sizeof(mess), what) < 0) {
1134 Error(
"AccessPathName",
"error receiving access confirmation");
1138 Info(
"AccessPathName",
"%s", mess);
1140 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