1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
// begin thread
boost::thread thread ( boost::bind ( _getfile, remote, local ) );
//thread.join ();
static size_t my_fwrite ( void *buffer, size_t size, size_t nmemb, void *stream )
{
CFTP::ftp_getfile
*out = ( CFTP::ftp_getfile * ) stream;
if ( out && !out -> fhandle )
{
/* open file for writing */
fopen_s ( &out -> fhandle, out -> filename, "wb" );
if ( !out -> fhandle )
return -1; /* failure, can't open file to write */
}
return fwrite ( buffer, size, nmemb, out -> fhandle );
}
void _getfile ( const char *remote, const char *local )
{
CFTP::ftp_getfile
ftpfile =
{
local,
remote,
NULL
};
CURL
*h;
CURLcode
r;
h = curl_easy_init ( );
if ( h != NULL )
{
char
info [ MAX_PATH + 100 ];
sprintf_s ( info, "ftp://%s/%s", Ftp.ServerName, remote );
curl_easy_setopt ( h, CURLOPT_URL, info );
sprintf_s ( info, sizeof info, "%s:%s", Ftp.UserName, Ftp.Password );
curl_easy_setopt ( h, CURLOPT_USERPWD, info );
curl_easy_setopt ( h, CURLOPT_WRITEFUNCTION, my_fwrite );
curl_easy_setopt ( h, CURLOPT_WRITEDATA, &ftpfile );
curl_easy_setopt ( h, CURLOPT_VERBOSE, 1L );
r = curl_easy_perform ( h );
curl_easy_cleanup ( h );logprintf ( " nu mldc turi but" );
if ( ftpfile.fhandle )
fclose ( ftpfile.fhandle );
if ( !r )
{
}
}
}
| |