#include <ftptrans.h>


Public Member Functions | |
| int | copyDirectory (const char *urlPrefix, const char *dir, const char *dest, const char *suffix) |
| FTPTransport (const char *host, StatusReporter *statusReporter=0) | |
| virtual std::vector< struct DirEntry > | getDirList (const char *dirURL) |
| virtual 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 () |
| virtual | ~FTPTransport () |
Protected Attributes | |
| SWBuf | host |
| SWBuf | p |
| bool | passive |
| StatusReporter * | statusReporter |
| bool | term |
| SWBuf | u |
TODO: document A base class to be used for reimplementation of network services.
Definition at line 50 of file ftptrans.h.
| FTPTransport::FTPTransport | ( | const char * | host, | |
| StatusReporter * | statusReporter = 0 | |||
| ) |
| FTPTransport::~FTPTransport | ( | ) | [virtual] |
Definition at line 70 of file ftptrans.cpp.
| int FTPTransport::copyDirectory | ( | const char * | urlPrefix, | |
| const char * | dir, | |||
| const char * | dest, | |||
| const char * | suffix | |||
| ) |
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] |
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 FTPTransport::getURL | ( | const char * | destPath, | |
| const char * | sourceURL, | |||
| SWBuf * | destBuf = 0 | |||
| ) | [virtual] |
Reimplemented in CURLFTPTransport, CURLHTTPTransport, and FTPLibFTPTransport.
Definition at line 75 of file ftptrans.cpp.
| void FTPTransport::setPassive | ( | bool | passive | ) | [inline] |
Definition at line 75 of file ftptrans.h.
| void FTPTransport::setPasswd | ( | const char * | passwd | ) | [inline] |
Definition at line 77 of file ftptrans.h.
00077 { p = passwd; }
| void FTPTransport::setUser | ( | const char * | user | ) | [inline] |
Definition at line 76 of file ftptrans.h.
00076 { u = user; }
| void FTPTransport::terminate | ( | ) | [inline] |
Definition at line 78 of file ftptrans.h.
00078 { term = true; }
SWBuf FTPTransport::host [protected] |
Definition at line 56 of file ftptrans.h.
SWBuf FTPTransport::p [protected] |
Definition at line 58 of file ftptrans.h.
bool FTPTransport::passive [protected] |
Definition at line 54 of file ftptrans.h.
StatusReporter* FTPTransport::statusReporter [protected] |
Definition at line 53 of file ftptrans.h.
bool FTPTransport::term [protected] |
Definition at line 55 of file ftptrans.h.
SWBuf FTPTransport::u [protected] |
Definition at line 57 of file ftptrans.h.
1.6.1