27 #include <curl/curl.h>
28 #include <curl/easy.h>
48 curl_global_init(CURL_GLOBAL_DEFAULT);
52 curl_global_cleanup();
81 static int my_fprogress(
void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow) {
84 SWLOGD(
"CURLFTPTransport report progress: totalSize: %ld; xfered: %ld\n", (
long)dltotal, (
long)dlnow);
86 if (dltotal < 0) dltotal = 0;
87 if (dlnow < 0) dlnow = 0;
88 if (dlnow > dltotal) dlnow = dltotal;
91 if (*(pd->
term))
return 1;
97 static int my_trace(CURL *handle, curl_infotype type,
unsigned char *data,
size_t size,
void *userp) {
103 case CURLINFO_TEXT: header =
"TEXT";
break;
104 case CURLINFO_HEADER_OUT: header =
"=> Send header";
break;
105 case CURLINFO_HEADER_IN: header =
"<= Recv header";
break;
108 case CURLINFO_DATA_OUT: header =
"=> Send data";
109 case CURLINFO_SSL_DATA_OUT: header =
"=> Send SSL data";
110 case CURLINFO_DATA_IN: header =
"<= Recv data";
111 case CURLINFO_SSL_DATA_IN: header =
"<= Recv SSL data";
116 if (size > 120) size = 120;
127 session = (CURL *)curl_easy_init();
137 signed char retVal = 0;
138 struct FtpFile ftpfile = {destPath, 0, destBuf};
144 struct MyProgressData pd;
148 curl_easy_setopt(
session, CURLOPT_URL, sourceURL);
150 SWBuf credentials =
u +
":" +
p;
151 curl_easy_setopt(
session, CURLOPT_USERPWD, credentials.
c_str());
154 curl_easy_setopt(
session, CURLOPT_FTPPORT,
"-");
155 curl_easy_setopt(
session, CURLOPT_NOPROGRESS, 0);
156 curl_easy_setopt(
session, CURLOPT_PROGRESSDATA, &pd);
162 curl_easy_setopt(
session, CURLOPT_FILE, &ftpfile);
165 curl_easy_setopt(
session, CURLOPT_VERBOSE,
true);
175 #if (LIBCURL_VERSION_MAJOR > 7) || \
176 ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR > 10)) || \
177 ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR == 10) && (LIBCURL_VERSION_PATCH >= 5))
178 # define EPRT_AVAILABLE 1
181 #ifdef EPRT_AVAILABLE
182 curl_easy_setopt(
session, CURLOPT_FTP_USE_EPRT, 0);
183 SWLOGD(
"***** using CURLOPT_FTP_USE_EPRT\n");
187 SWLOGD(
"***** About to perform curl easy action. \n");
188 SWLOGD(
"***** destPath: %s \n", destPath);
189 SWLOGD(
"***** sourceURL: %s \n", sourceURL);
190 res = curl_easy_perform(
session);
191 SWLOGD(
"***** Finished performing curl easy action. \n");
194 curl_easy_setopt(
session, CURLOPT_PROGRESSDATA, (
void*)
NULL);
196 if (CURLE_OK != res) {
197 if (CURLE_OPERATION_TIMEDOUT == res
199 #ifdef CURLE_FTP_ACCEPT_TIMEOUT
200 || CURLE_FTP_ACCEPT_TIMEOUT == res
#define SWORD_NAMESPACE_START
virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf=0)
static int my_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp)
static void closeFile(int fd)
static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
CURLFTPTransport(const char *host, StatusReporter *statusReporter=0)
static int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
const char * c_str() const
unsigned long size() const
virtual void update(unsigned long totalBytes, unsigned long completedBytes)
static long write(int fd, const void *buf, long count)
static int createPathAndFile(const char *fName)
static class SWORD_NAMESPACE_START::CURLFTPTransport_init _curlFTPTransport_init
#define SWORD_NAMESPACE_END
StatusReporter * statusReporter