diff --git a/CREDITS b/CREDITS index 621a32d..3a1ba46 100644 --- a/CREDITS +++ b/CREDITS @@ -1,3 +1,4 @@ Thomas Pfau (ftplib author) Eli Moulton (bugfix) wangxi19 (bugfix) +Fojtik (bugfix) diff --git a/ftplib.cpp b/ftplib.cpp index 36e0176..eaab214 100755 --- a/ftplib.cpp +++ b/ftplib.cpp @@ -49,14 +49,6 @@ typedef int socklen_t; #define strdup _strdup #endif -#ifndef NOLFS -#define _fseek fseek -#define _fopen fopen -#else -#define _fseek fseeko64 -#define _fopen fopen64 -#endif - using namespace std; /* socket values */ @@ -139,6 +131,14 @@ ftplib::~ftplib() free(mp_ftphandle); } +void ftplib::sprint_rest(char *buf, off64_t offset) { +#if defined(__APPLE__) + sprintf(buf,"REST %lld",offset); +#else + sprintf(buf,"REST %ld",offset); +#endif +} + /* * socket_wait - wait for socket to receive or flush data * @@ -627,7 +627,7 @@ int ftplib::FtpAcceptConnection(ftphandle *nData, ftphandle *nControl) int ftplib::FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData) { char buf[256]; - int dir, ret; + int dir; if ((path == NULL) && ((type == ftplib::filewrite) || (type == ftplib::fileread) @@ -788,7 +788,7 @@ int ftplib::FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mod if (mp_ftphandle->offset != 0) { char buf[256]; - sprintf(buf,"REST %lld", mp_ftphandle->offset); + sprint_rest(buf, mp_ftphandle->offset); if (!FtpSendCmd(buf,'3',nControl)) { net_close(sData); @@ -892,7 +892,7 @@ int ftplib::FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mod if (mp_ftphandle->offset != 0) { char buf[256]; - sprintf(buf,"REST %lld",mp_ftphandle->offset); + sprint_rest(buf, mp_ftphandle->offset); if (!FtpSendCmd(buf,'3',nControl)) return 0; } @@ -1187,7 +1187,7 @@ int ftplib::Pwd(char *path, int max) if (s == NULL) return 0; s++; while ((--l) && (*s) && (*s != '"')) *b++ = *s++; - *b++ = '\0'; + *b = '\0'; return 1; } @@ -1202,7 +1202,6 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl char *dbuf; FILE *local = NULL; ftphandle *nData; - int rv=1; // 3.1-1 if (localfile != NULL) { @@ -1214,13 +1213,13 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl if (type == ftplib::filewrite) { ac[0] = 'r'; ac[1] = '\0'; } if (mode == ftplib::image) ac[1] = 'b'; - local = _fopen(localfile, ac); + local = fopen64(localfile, ac); if (local == NULL) { strncpy(nControl->response, strerror(errno), sizeof(nControl->response)); return 0; } - if (type == ftplib::filewriteappend) _fseek(local,mp_ftphandle->offset,SEEK_SET); + if (type == ftplib::filewriteappend) fseeko64(local,mp_ftphandle->offset,SEEK_SET); } if (local == NULL) local = ((type == ftplib::filewrite) || (type == ftplib::filewriteappend)) ? stdin : stdout; @@ -1237,7 +1236,6 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl if ((c = FtpWrite(dbuf, l, nData)) < l) { printf("short write: passed %d, wrote %d\n", l, c); - rv = 0; break; } } diff --git a/ftplib.h b/ftplib.h index 602eae2..45a7e84 100755 --- a/ftplib.h +++ b/ftplib.h @@ -43,6 +43,8 @@ #ifdef NOLFS #define off64_t long +#define fseeko64 fseek +#define fopen64 fopen #endif #if defined(__APPLE__) @@ -102,7 +104,7 @@ struct ftphandle { bool correctpasv; }; -#if defined(_WIN32) +#if defined(_WIN32) class DLLIMPORT ftplib { #else class ftplib { @@ -117,7 +119,7 @@ class ftplib { filewrite, filereadappend, filewriteappend - }; + }; enum transfermode { @@ -137,74 +139,72 @@ class ftplib { alternativefxp }; - enum dataencryption - { - unencrypted = 0, - secure - }; - - ftplib(); - ~ftplib(); - char* LastResponse(); - int Connect(const char *host); - int Login(const char *user, const char *pass); - int Site(const char *cmd); - int Raw(const char *cmd); - int SysType(char *buf, int max); - int Mkdir(const char *path); - int Chdir(const char *path); - int Cdup(); - int Rmdir(const char *path); - int Pwd(char *path, int max); - int Nlst(const char *outputfile, const char *path); - int Dir(const char *outputfile, const char *path); - int Size(const char *path, int *size, transfermode mode); - int ModDate(const char *path, char *dt, int max); - int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0); - int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0); - int Rename(const char *src, const char *dst); - int Delete(const char *path); -#ifndef NOSSL - int SetDataEncryption(dataencryption enc); - int NegotiateEncryption(); - void SetCallbackCertFunction(FtpCallbackCert pointer); + enum dataencryption + { + unencrypted = 0, + secure + }; + + ftplib(); + ~ftplib(); + char* LastResponse(); + int Connect(const char *host); + int Login(const char *user, const char *pass); + int Site(const char *cmd); + int Raw(const char *cmd); + int SysType(char *buf, int max); + int Mkdir(const char *path); + int Chdir(const char *path); + int Cdup(); + int Rmdir(const char *path); + int Pwd(char *path, int max); + int Nlst(const char *outputfile, const char *path); + int Dir(const char *outputfile, const char *path); + int Size(const char *path, int *size, transfermode mode); + int ModDate(const char *path, char *dt, int max); + int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0); + int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0); + int Rename(const char *src, const char *dst); + int Delete(const char *path); +#ifndef NOSSL + int SetDataEncryption(dataencryption enc); + int NegotiateEncryption(); + void SetCallbackCertFunction(FtpCallbackCert pointer); #endif - int Quit(); - void SetCallbackIdleFunction(FtpCallbackIdle pointer); - void SetCallbackLogFunction(FtpCallbackLog pointer); - void SetCallbackXferFunction(FtpCallbackXfer pointer); - void SetCallbackArg(void *arg); - void SetCallbackBytes(off64_t bytes); - void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; }; - void SetCallbackIdletime(int time); - void SetConnmode(connmode mode); - static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method); - - ftphandle* RawOpen(const char *path, accesstype type, transfermode mode); - int RawClose(ftphandle* handle); - int RawWrite(void* buf, int len, ftphandle* handle); - int RawRead(void* buf, int max, ftphandle* handle); + int Quit(); + void SetCallbackIdleFunction(FtpCallbackIdle pointer); + void SetCallbackLogFunction(FtpCallbackLog pointer); + void SetCallbackXferFunction(FtpCallbackXfer pointer); + void SetCallbackArg(void *arg); + void SetCallbackBytes(off64_t bytes); + void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; }; + void SetCallbackIdletime(int time); + void SetConnmode(connmode mode); + static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method); + ftphandle* RawOpen(const char *path, accesstype type, transfermode mode); + int RawClose(ftphandle* handle); + int RawWrite(void* buf, int len, ftphandle* handle); + int RawRead(void* buf, int max, ftphandle* handle); private: - ftphandle* mp_ftphandle; - - int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode); - int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); - int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl); - int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl); - int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); - int FtpRead(void *buf, int max, ftphandle *nData); - int FtpWrite(void *buf, int len, ftphandle *nData); - int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData); - int FtpClose(ftphandle *nData); - - int socket_wait(ftphandle *ctl); - int readline(char *buf,int max,ftphandle *ctl); - int writeline(char *buf, int len, ftphandle *nData); - int readresp(char c, ftphandle *nControl); - - void ClearHandle(); - int CorrectPasvResponse(unsigned char *v); + ftphandle* mp_ftphandle; + + int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode); + int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); + int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl); + int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl); + int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); + int FtpRead(void *buf, int max, ftphandle *nData); + int FtpWrite(void *buf, int len, ftphandle *nData); + int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData); + int FtpClose(ftphandle *nData); + int socket_wait(ftphandle *ctl); + int readline(char *buf,int max,ftphandle *ctl); + int writeline(char *buf, int len, ftphandle *nData); + int readresp(char c, ftphandle *nControl); + void sprint_rest(char *buf, off64_t offset); + void ClearHandle(); + int CorrectPasvResponse(unsigned char *v); }; -#endif \ No newline at end of file +#endif