/* header #include <curl/curl.h> */
{
/* header #include <curl/curl.h> */
/* ftp upload to server file binary */
curl_global_init( CURL_GLOBAL_ALL ) ;
CURL *curl_handle = curl_easy_init() ;
if( NULL == curl_handle ){
return false;
}
long fzize = QuoInfo.size(); /* file size */
/* ftpfile = c:\image.jpg / remotefile = ftp://username:pass@host.com:21/path/image.jpg /path/ related to ftp login */
/* url = ftp:{login}:{password}@{host}:21{dated dir}{data remotefile} */
char *localfile = lop.data();
FILE *putfile;
putfile = fopen(localfile, "rb"); /* binary image! */
char *url = ba.data();
/*
qDebug() << "### localfile " << localfile;
qDebug() << "### Puturl " << url;
*/
/* handy for debugging: see *everything* that goes on */
/* curl_easy_setopt( curl_handle , CURLOPT_VERBOSE, 1 ) ; */ /* open to debug to sea actions */
// target url:
curl_easy_setopt( curl_handle , CURLOPT_URL, url ) ;
// no progress bar:
curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS , 1 ) ;
// use passive FTP, if it's available
curl_easy_setopt(curl_handle,CURLOPT_FTP_USE_EPSV , 1 ) ;
curl_easy_setopt(curl_handle,CURLOPT_TIMEOUT , 15 ); /* put on server config qwidget */
curl_easy_setopt(curl_handle,CURLOPT_UPLOAD , 1 );
curl_easy_setopt(curl_handle,CURLOPT_INFILE , putfile );
curl_easy_setopt(curl_handle,CURLOPT_INFILESIZE , fzize );
/* make action */
if (curl_easy_perform(curl_handle)==CURLE_OK) {
curl_easy_cleanup( curl_handle );
curl_global_cleanup();
return true;
} else {
return false;
}
}
// yes, it's "mkd" and not "mkdir" (many clients translate it for you)
// see RFC 959 for details:
//
// http://www.ietf.org/rfc/rfc959.txt
//
// NOTE: creating/changing to the dir isn't necessary here; it's done as
// part of the example of using CURLOPT_QUOTE. You could simply have
// specified CURLOPT_FTP_CREATE_MISSING_DIRS.
commandBuf << "mkd " << remotePath << std::flush ;
const std::string mkdirCommand = commandBuf.str() ;
commands = curl_slist_append( commands , mkdirCommand.c_str() ) ;
// NOTE: cURL will try to change dirs (based on the URL)
// from the present directory (by default, your home dir
// on the remote system).
// To upload data to an absolute path on the remote host,
// you must change to the root dir first.
commands = curl_slist_append( commands , "cwd /" ) ;
// from here, cURL will "cwd tmp" and "cwd {timestamp dir}"