32 # include <sys/types.h> 47 #if defined(R__UNIX) || defined(R__MACOSX) 52 # include <sys/mman.h> 82 "url must be of the form \"[root[up,s,k,g,h,ug]://]host[:port]\"");
99 if (hurl.Contains(
"root")) {
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)
235 if (!
IsOpen() || !file || !*file)
return -1;
237 #if defined(R__WIN32) || defined(R__WINGCC) 239 #elif defined(R__SEEK64) 240 Int_t fd = open64(file, O_RDONLY);
245 Error(
"PutFile",
"cannot open %s in read mode", file);
250 Long_t id, flags, modtime;
253 Error(
"PutFile",
"%s not a regular file (%ld)", file, flags);
258 Warning(
"PutFile",
"could not stat %s", file);
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);
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",
408 if (!
IsOpen() || !file || !*file)
return -1;
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);
542 if (n !=
Int_t(left-skip)) {
543 Error(
"GetFile",
"error receiving buffer of length %d, got %d",
544 Int_t(left-skip), n);
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",
578 localName, (
Long_t)siz, n);
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);
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");
843 Info(
"DeleteFile",
"%s", mess);
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);
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;
1061 Long_t id, flags, dev, ino, mtime;
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))
void PrintError(const char *where, Int_t err) const
Print error string depending on error code.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
double read(const std::string &file_name)
reading
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
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.
R__EXTERN const char * gRootdErrStr[]
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
This class represents a WWW compatible URL.
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 Int_t Recv(TMessage *&mess)
Receive a TMessage object.
const char * GetProtocol() 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...
Int_t DeleteFile(const char *file) const
Delete a remote file.
R__EXTERN TVirtualMutex * gROOTMutex
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
TString & Insert(Ssiz_t pos, const char *s)
static Int_t GetErrno()
Static function returning system error number.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
const char * GetHost() const
Long64_t GetFile(const char *file, const char *localName=0)
Transfer file from remote host.
Int_t ChangeDirectory(const char *dir) const
Change the remote directory.
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...
static Long64_t fgBytesWrite
Int_t GetRemoteProtocol() const
Long64_t fBytesWrite
connection to rootd
void Error(const char *location, const char *msgfmt,...)
virtual ~TFTP()
TFTP dtor. Send close message and close socket.
const char * GetUser() const
const char * GetUser() const
Int_t ListDirectory(Option_t *cmd="") const
List remote directory.
Int_t ChangePermission(const char *file, Int_t mode) const
Change permissions of a remote file.
static Long64_t fgBytesRead
R__EXTERN TSystem * gSystem
Int_t Recv(Int_t &status, EMessageTypes &kind) const
Return status from rootd server and message kind.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
virtual const char * AsString(TString &out)
Returns short string with relevant information about this security context.
Int_t RenameFile(const char *file1, const char *file2) const
Rename a remote file.
Long64_t PutFile(const char *file, const char *remoteName=0)
Transfer file to remote host.
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
#define R__LOCKGUARD2(mutex)
void Print(Option_t *opt="") const
Print some info about the FTP connection.
virtual const char * HostName()
Return the system's host name.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Bool_t IsAuthenticated() const
Int_t Close()
Close ftp connection.
void SetBlockSize(Int_t blockSize)
Make sure the block size is a power of two, with a minimum of 32768.
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.
TSecContext * GetSecContext() const
Int_t PrintDirectory() const
Print path of remote working directory.
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.
static void ResetErrno()
Static function resetting system error number.
Int_t DeleteDirectory(const char *dir) const
Delete a remote directory.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
static char * skip(char **buf, const char *delimiters)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
const char * Data() const