54 if (out && !out->stream && !out->destBuf) {
56 out->stream=fopen(out->filename,
"wb");
61 int s = (int)out->destBuf->size();
62 out->destBuf->size(s+(size*nmemb));
63 memcpy(out->destBuf->getRawData()+s,
buffer, size*nmemb);
66 return (
int)fwrite(buffer, size, nmemb, out->stream);
70 struct MyProgressData {
76 static int my_fprogress(
void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow) {
79 SWLOGD(
"RTransportGDrive report progress: totalSize: %ld; xfered: %ld\n", (
long)dltotal, (
long)dlnow);
81 if (dltotal < 0) dltotal = 0;
82 if (dlnow < 0) dlnow = 0;
83 if (dlnow > dltotal) dlnow = dltotal;
84 pd->sr->update(dltotal, dlnow);
86 if (*(pd->term))
return 1;
107 signed char retVal = 0;
108 struct FtpFile ftpfile = {destPath, 0, destBuf};
115 struct MyProgressData pd;
119 curl_easy_setopt(session, CURLOPT_URL, sourceURL);
121 SWBuf credentials =
u +
":" +
p;
122 curl_easy_setopt(session, CURLOPT_USERPWD, credentials.
c_str());
123 curl_easy_setopt(session, CURLOPT_WRITEFUNCTION,
my_fwrite);
125 curl_easy_setopt(session, CURLOPT_FTPPORT,
"-");
126 curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
127 curl_easy_setopt(session, CURLOPT_PROGRESSDATA, &pd);
128 curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION,
my_fprogress);
129 curl_easy_setopt(session, CURLOPT_DEBUGFUNCTION,
my_trace);
131 curl_easy_setopt(session, CURLOPT_FILE, &ftpfile);
134 curl_easy_setopt(session, CURLOPT_VERBOSE,
true);
135 curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT, 45);
139 #if (LIBCURL_VERSION_MAJOR > 7) || \
140 ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR > 10)) || \
141 ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR == 10) && (LIBCURL_VERSION_PATCH >= 5))
142 # define EPRT_AVAILABLE 1
145 #ifdef EPRT_AVAILABLE
146 curl_easy_setopt(session, CURLOPT_FTP_USE_EPRT, 0);
147 SWLOGD(
"***** using CURLOPT_FTP_USE_EPRT\n");
151 SWLOGD(
"***** About to perform curl easy action. \n");
152 SWLOGD(
"***** destPath: %s \n", destPath);
153 SWLOGD(
"***** sourceURL: %s \n", sourceURL);
154 res = curl_easy_perform(session);
155 SWLOGD(
"***** Finished performing curl easy action. \n");
158 curl_easy_setopt(session, CURLOPT_PROGRESSDATA, (
void*)
NULL);
160 if(CURLE_OK != res) {
167 fclose(ftpfile.stream);
#define SWORD_NAMESPACE_START
virtual char putURL(const char *destURL, const char *sourcePath, SWBuf *sourceBuf=0)
RTransportGDrive(const char *host, StatusReporter *statusReporter=0)
static int my_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp)
static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
static int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
const char * c_str() const
virtual char putURL(const char *destURL, const char *sourcePath, SWBuf *sourceBuf=0)
#define SWORD_NAMESPACE_END
static class SWORD_NAMESPACE_START::RTransportGDrive_init _rTransportGDrive_init
StatusReporter * statusReporter
virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf=0)