#include <ftplibftpt.h>


Public Member Functions | |
| int | copyDirectory (const char *urlPrefix, const char *dir, const char *dest, const char *suffix) |
| FTPLibFTPTransport (const char *host, StatusReporter *statusReporter=0) | |
| virtual std::vector< struct DirEntry > | getDirList (const char *dirURL) |
| char | getURL (const char *destPath, const char *sourceURL, SWBuf *destBuf=0) |
| void | setPassive (bool passive) |
| void | setPasswd (const char *passwd) |
| void | setUser (const char *user) |
| void | terminate () |
| ~FTPLibFTPTransport () | |
Protected Attributes | |
| SWBuf | host |
| SWBuf | p |
| bool | passive |
| StatusReporter * | statusReporter |
| bool | term |
| SWBuf | u |
Private Member Functions | |
| char | assureLoggedIn () |
Private Attributes | |
| netbuf * | ftpConnection |
Definition at line 40 of file ftplibftpt.h.
| FTPLibFTPTransport::FTPLibFTPTransport | ( | const char * | host, | |
| StatusReporter * | statusReporter = 0 | |||
| ) |
Definition at line 79 of file ftplibftpt.cpp.
00079 : FTPTransport(host, sr) { 00080 00081 ftpConnection = 0; 00082 }
| FTPLibFTPTransport::~FTPLibFTPTransport | ( | ) |
Definition at line 85 of file ftplibftpt.cpp.
00085 { 00086 if (ftpConnection) 00087 FtpQuit(ftpConnection); 00088 }
| char FTPLibFTPTransport::assureLoggedIn | ( | ) | [private] |
Definition at line 91 of file ftplibftpt.cpp.
00091 { 00092 char retVal = 0; 00093 if (ftpConnection == 0) { 00094 SWLog::getSystemLog()->logDebug("connecting to host: %s...\n", host.c_str()); 00095 if (FtpConnect(host, &ftpConnection)) { 00096 FtpOptions(FTPLIB_CONNMODE, (passive) ? FTPLIB_PASSIVE : FTPLIB_PORT, ftpConnection); 00097 00098 SWLog::getSystemLog()->logDebug("connected. logging in...\n"); 00099 if (FtpLogin(u.c_str(), p.c_str(), ftpConnection)) { 00100 SWLog::getSystemLog()->logDebug("logged in.\n"); 00101 retVal = 0; 00102 } 00103 else { 00104 SWLog::getSystemLog()->logError("Failed to login to %s\n", host.c_str()); 00105 retVal = -2; 00106 } 00107 } 00108 else { 00109 SWLog::getSystemLog()->logError("Failed to connect to %s\n", host.c_str()); 00110 retVal = -1; 00111 } 00112 } 00113 return retVal; 00114 }
| int FTPTransport::copyDirectory | ( | const char * | urlPrefix, | |
| const char * | dir, | |||
| const char * | dest, | |||
| const char * | suffix | |||
| ) | [inherited] |
Definition at line 125 of file ftptrans.cpp.
00125 { 00126 unsigned int i; 00127 int retVal = 0; 00128 00129 SWBuf url = SWBuf(urlPrefix) + SWBuf(dir); 00130 removeTrailingSlash(url); 00131 url += '/'; 00132 00133 SWLog::getSystemLog()->logWarning("NetTransport: getting dir %s\n", url.c_str()); 00134 vector<struct DirEntry> dirList = getDirList(url.c_str()); 00135 00136 if (!dirList.size()) { 00137 SWLog::getSystemLog()->logWarning("NetTransport: failed to read dir %s\n", url.c_str()); 00138 return -1; 00139 } 00140 00141 long totalBytes = 0; 00142 for (i = 0; i < dirList.size(); i++) 00143 totalBytes += dirList[i].size; 00144 long completedBytes = 0; 00145 for (i = 0; i < dirList.size(); i++) { 00146 struct DirEntry &dirEntry = dirList[i]; 00147 SWBuf buffer = (SWBuf)dest; 00148 removeTrailingSlash(buffer); 00149 buffer += "/"; 00150 buffer += dirEntry.name; 00151 if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) { 00152 SWBuf buffer2 = "Downloading ("; 00153 buffer2.appendFormatted("%d", i+1); 00154 buffer2 += " of "; 00155 buffer2.appendFormatted("%d", dirList.size()); 00156 buffer2 += "): "; 00157 buffer2 += dirEntry.name; 00158 if (statusReporter) 00159 statusReporter->preStatus(totalBytes, completedBytes, buffer2.c_str()); 00160 FileMgr::createParent(buffer.c_str()); // make sure parent directory exists 00161 SWTRY { 00162 SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir; 00163 removeTrailingSlash(url); 00164 url += "/"; 00165 url += dirEntry.name; //dont forget the final slash 00166 if (!dirEntry.isDirectory) { 00167 if (getURL(buffer.c_str(), url.c_str())) { 00168 SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", url.c_str()); 00169 return -2; 00170 } 00171 completedBytes += dirEntry.size; 00172 } 00173 else { 00174 SWBuf subdir = (SWBuf)dir; 00175 removeTrailingSlash(subdir); 00176 subdir += (SWBuf)"/" + dirEntry.name; 00177 if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) { 00178 SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", subdir.c_str()); 00179 return -2; 00180 } 00181 } 00182 } 00183 SWCATCH (...) {} 00184 if (term) { 00185 retVal = -3; 00186 break; 00187 } 00188 } 00189 } 00190 return retVal; 00191 }
| vector< struct DirEntry > FTPTransport::getDirList | ( | const char * | dirURL | ) | [virtual, inherited] |
Reimplemented in CURLHTTPTransport.
Definition at line 81 of file ftptrans.cpp.
00081 { 00082 00083 vector<struct DirEntry> dirList; 00084 00085 SWBuf dirBuf; 00086 if (!getURL("", dirURL, &dirBuf)) { 00087 char *start = dirBuf.getRawData(); 00088 char *end = start; 00089 while (start < (dirBuf.getRawData()+dirBuf.size())) { 00090 struct ftpparse item; 00091 bool looking = true; 00092 for (end = start; *end; end++) { 00093 if (looking) { 00094 if ((*end == 10) || (*end == 13)) { 00095 *end = 0; 00096 looking = false; 00097 } 00098 } 00099 else if ((*end != 10) && (*end != 13)) 00100 break; 00101 } 00102 SWLog::getSystemLog()->logWarning("FTPURLGetDir: parsing item %s(%d)\n", start, end-start); 00103 int status = ftpparse(&item, start, end - start); 00104 // in ftpparse.h, there is a warning that name is not necessarily null terminated 00105 SWBuf name; 00106 name.append(item.name, item.namelen); 00107 SWLog::getSystemLog()->logWarning("FTPURLGetDir: got item %s\n", name.c_str()); 00108 if (status && name != "." && name != "..") { 00109 struct DirEntry i; 00110 i.name = name; 00111 i.size = item.size; 00112 i.isDirectory = (item.flagtrycwd == 1); 00113 dirList.push_back(i); 00114 } 00115 start = end; 00116 } 00117 } 00118 else { 00119 SWLog::getSystemLog()->logWarning("FTPURLGetDir: failed to get dir %s\n", dirURL); 00120 } 00121 return dirList; 00122 }
| char FTPLibFTPTransport::getURL | ( | const char * | destPath, | |
| const char * | sourceURL, | |||
| SWBuf * | destBuf = 0 | |||
| ) | [virtual] |
Reimplemented from FTPTransport.
Definition at line 117 of file ftplibftpt.cpp.
00117 { 00118 00119 char retVal = 0; 00120 00121 SWLog::getSystemLog()->logDebug("FTPLibFTPTransport::getURL(%s, %s, ...);\n", (destPath)?destPath:"(null)", sourceURL); 00122 // assert we can login 00123 retVal = assureLoggedIn(); 00124 if (retVal) return retVal; 00125 SWLog::getSystemLog()->logDebug("FTPLibFTPTransport - logged in.\n"); 00126 00127 SWBuf sourcePath = sourceURL; 00128 00129 SWBuf outFile; 00130 if (!destBuf) { 00131 outFile = destPath; 00132 } 00133 00134 sourcePath << (6 + host.length()); // shift << "ftp://hostname"; 00135 SWLog::getSystemLog()->logDebug("getting file %s to %s\n", sourcePath.c_str(), destBuf ? "*internal buffer*" : outFile.c_str()); 00136 struct MyProgressData pd; 00137 pd.sr = statusReporter; 00138 pd.term = &term; 00139 pd.totalSize = 0; 00140 00141 if (destBuf) { 00142 FtpOptions(FTPLIB_CALLBACK_WRITER, (long)&my_swbufwriter, ftpConnection); 00143 FtpOptions(FTPLIB_CALLBACK_WRITERARG, (long)destBuf, ftpConnection); 00144 } 00145 else { 00146 FtpOptions(FTPLIB_CALLBACK_WRITER, 0L, ftpConnection); 00147 } 00148 00149 FtpOptions(FTPLIB_CALLBACK, (long)&my_fprogress, ftpConnection); 00150 FtpOptions(FTPLIB_CALLBACKARG, (long)&pd, ftpConnection); 00151 FtpOptions(FTPLIB_CALLBACKBYTES, (long)2048, ftpConnection); 00152 00153 if (sourcePath.endsWith("/") || sourcePath.endsWith("\\")) { 00154 // SWLog::getSystemLog()->logDebug("getting test directory %s\n", sourcePath.c_str()); 00155 // FtpDir(NULL, sourcePath, ftpConnection); 00156 SWLog::getSystemLog()->logDebug("getting real directory %s\n", sourcePath.c_str()); 00157 retVal = FtpDir(destBuf ? 0 : outFile.c_str(), sourcePath, ftpConnection) - 1; 00158 SWLog::getSystemLog()->logDebug("got real directory %s to %s\n", sourcePath.c_str(), destBuf ? "*internal buffer*" : outFile.c_str()); 00159 } 00160 else { 00161 SWLog::getSystemLog()->logDebug("getting file %s\n", sourcePath.c_str()); 00162 int size; 00163 FtpSize(sourcePath, &size, FTPLIB_IMAGE, ftpConnection); 00164 pd.totalSize = size; 00165 retVal = FtpGet(destBuf ? 0 : outFile.c_str(), sourcePath, FTPLIB_IMAGE, ftpConnection) - 1; 00166 } 00167 00168 SWLog::getSystemLog()->logDebug("FTPLibFTPTransport - returning: %d\n", retVal); 00169 return retVal; 00170 }
| void FTPTransport::setPassive | ( | bool | passive | ) | [inline, inherited] |
Definition at line 75 of file ftptrans.h.
| void FTPTransport::setPasswd | ( | const char * | passwd | ) | [inline, inherited] |
Definition at line 77 of file ftptrans.h.
00077 { p = passwd; }
| void FTPTransport::setUser | ( | const char * | user | ) | [inline, inherited] |
Definition at line 76 of file ftptrans.h.
00076 { u = user; }
| void FTPTransport::terminate | ( | ) | [inline, inherited] |
Definition at line 78 of file ftptrans.h.
00078 { term = true; }
netbuf* FTPLibFTPTransport::ftpConnection [private] |
Definition at line 41 of file ftplibftpt.h.
SWBuf FTPTransport::host [protected, inherited] |
Definition at line 56 of file ftptrans.h.
SWBuf FTPTransport::p [protected, inherited] |
Definition at line 58 of file ftptrans.h.
bool FTPTransport::passive [protected, inherited] |
Definition at line 54 of file ftptrans.h.
StatusReporter* FTPTransport::statusReporter [protected, inherited] |
Definition at line 53 of file ftptrans.h.
bool FTPTransport::term [protected, inherited] |
Definition at line 55 of file ftptrans.h.
SWBuf FTPTransport::u [protected, inherited] |
Definition at line 57 of file ftptrans.h.
1.6.1