summaryrefslogtreecommitdiff
path: root/src/mgr/remotetrans.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgr/remotetrans.cpp')
-rw-r--r--src/mgr/remotetrans.cpp77
1 files changed, 49 insertions, 28 deletions
diff --git a/src/mgr/remotetrans.cpp b/src/mgr/remotetrans.cpp
index 03ad3e4..2d14d8f 100644
--- a/src/mgr/remotetrans.cpp
+++ b/src/mgr/remotetrans.cpp
@@ -1,8 +1,8 @@
-/*****************************************************************************
+/*****************************************************************************
*
* remotetrans.cpp -
*
- * $Id: remotetrans.cpp 2980 2013-09-14 21:51:47Z scribe $
+ * $Id: remotetrans.cpp 3515 2017-11-01 11:38:09Z scribe $
*
* Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -65,6 +65,8 @@ RemoteTransport::RemoteTransport(const char *host, StatusReporter *statusReporte
u = "ftp";
p = "installmgr@user.com";
term = false;
+ passive = true;
+ unverifiedPeerAllowed = true;
}
@@ -74,13 +76,22 @@ RemoteTransport::~RemoteTransport() {
// override this method in your real transport class
char RemoteTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
- char retVal = 0;
+ SWLog::getSystemLog()->logWarning("RemoteTransport::getURL called but unsupported");
+ char retVal = -1;
+ return retVal;
+}
+
+// override this method in your real transport class
+char RemoteTransport::putURL(const char *destURL, const char *sourcePath, SWBuf *sourceBuf) {
+ SWLog::getSystemLog()->logWarning("RemoteTransport::putURL called but unsupported");
+ char retVal = -1;
return retVal;
}
vector<struct DirEntry> RemoteTransport::getDirList(const char *dirURL) {
+ SWLog::getSystemLog()->logDebug("RemoteTransport::getDirList(%s)", dirURL);
vector<struct DirEntry> dirList;
SWBuf dirBuf;
@@ -100,12 +111,12 @@ vector<struct DirEntry> RemoteTransport::getDirList(const char *dirURL) {
else if ((*end != 10) && (*end != 13))
break;
}
- SWLog::getSystemLog()->logWarning("getDirList: parsing item %s(%d)\n", start, end-start);
- int status = ftpparse(&item, start, end - start);
+ SWLog::getSystemLog()->logDebug("getDirList: parsing item %s(%d)\n", start, end-start);
+ int status = ftpparse(&item, start, (int)(end - start));
// in ftpparse.h, there is a warning that name is not necessarily null terminated
SWBuf name;
name.append(item.name, item.namelen);
- SWLog::getSystemLog()->logWarning("getDirList: got item %s\n", name.c_str());
+ SWLog::getSystemLog()->logDebug("getDirList: got item %s\n", name.c_str());
if (status && name != "." && name != "..") {
struct DirEntry i;
i.name = name;
@@ -124,24 +135,45 @@ vector<struct DirEntry> RemoteTransport::getDirList(const char *dirURL) {
int RemoteTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
- unsigned int i;
+ SWLog::getSystemLog()->logDebug("RemoteTransport::copyDirectory");
int retVal = 0;
-
+
SWBuf url = SWBuf(urlPrefix) + SWBuf(dir);
removeTrailingSlash(url);
url += '/';
- SWLog::getSystemLog()->logWarning("NetTransport: getting dir %s\n", url.c_str());
+ SWLog::getSystemLog()->logDebug("NetTransport: getting dir %s\n", url.c_str());
vector<struct DirEntry> dirList = getDirList(url.c_str());
if (!dirList.size()) {
SWLog::getSystemLog()->logWarning("NetTransport: failed to read dir %s\n", url.c_str());
return -1;
}
-
+
+ // append files in sub directories and calculate total download size
+ unsigned int i = 0;
long totalBytes = 0;
- for (i = 0; i < dirList.size(); i++)
- totalBytes += dirList[i].size;
+ for (;;) {
+ if (i == dirList.size())
+ break;
+
+ struct DirEntry &e = dirList.at(i);
+
+ if (e.isDirectory) {
+ SWBuf name(e.name); // &e will be invalidated after first insertion
+ vector<struct DirEntry> sd = getDirList((url + name + '/').c_str());
+ for (unsigned int ii = 0; ii < sd.size(); ii++) {
+ sd[ii].name = name + '/' + sd[ii].name;
+ dirList.push_back(sd[ii]);
+ }
+ dirList.erase(dirList.begin() + i);
+ }
+ else {
+ totalBytes += e.size;
+ i++;
+ }
+ }
+
long completedBytes = 0;
for (i = 0; i < dirList.size(); i++) {
struct DirEntry &dirEntry = dirList[i];
@@ -163,23 +195,12 @@ int RemoteTransport::copyDirectory(const char *urlPrefix, const char *dir, const
SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir;
removeTrailingSlash(url);
url += "/";
- url += dirEntry.name; //dont forget the final slash
- if (!dirEntry.isDirectory) {
- if (getURL(buffer.c_str(), url.c_str())) {
- SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", url.c_str());
- return -2;
- }
- completedBytes += dirEntry.size;
- }
- else {
- SWBuf subdir = (SWBuf)dir;
- removeTrailingSlash(subdir);
- subdir += (SWBuf)"/" + dirEntry.name;
- if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) {
- SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", subdir.c_str());
- return -2;
- }
+ url += dirEntry.name;
+ if (getURL(buffer.c_str(), url.c_str())) {
+ SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", url.c_str());
+ return -2;
}
+ completedBytes += dirEntry.size;
}
SWCATCH (...) {}
if (term) {