( IMO hingegen imap , smtp-auth immer codiert sind... )
Gibt es eine variante zum server zu uploaden ohne dass pass zu zeigen?
Ich lade mit libcurl zum server ..... in einen "console" programm dass nur einen slot hat ( QTimer::singleShot(5000, this, SLOT(ShowTimer())); ) da dass programm immer aktiv ist .... wie ein cron job...
UploadFileServer("c:\image.jpg","ftp://user:pass@domain.ex:21/tmp/image.jpg");
Code: Alles auswählen
bool Qjobs::UploadFileServer( QString ftpfile , QString remotefile )
{
curl_global_init( CURL_GLOBAL_ALL ) ;
CURL *curl_handle = curl_easy_init() ;
if( NULL == curl_handle ){
return false;
}
QFileInfo QuoInfo(ftpfile);
long fzize = QuoInfo.size(); /* file size */
/* url = ftp:{ftpfile} UploadFileServer function based on config */
/* url = ftp:{login}:{password}@{host}:21{dated dir}{data remotefile} */
QByteArray lop = ftpfile.toAscii();
QByteArray ba = remotefile.toAscii();
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 , 10 ); /* 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;
}
}