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
|
int CFTP::TryLogin ( )
{
if ( ServerName == NULL || UserName == NULL || Password == NULL )
return 0;
Handle = curl_easy_init ( );
if ( Handle == NULL )
return 0;
char
info [ 150 ];
sprintf_s ( info, sizeof info, "ftp://%s/", ServerName );
if ( curl_easy_setopt ( Handle, CURLOPT_URL, info ) )
{
curl_easy_cleanup ( Handle );
return 0;
}
sprintf_s ( info, sizeof info, "%s:%s", UserName, Password );
if ( curl_easy_setopt ( Handle, CURLOPT_USERPWD, info ) )
{
curl_easy_cleanup ( Handle );
return 0;
}
return 1;
}
int CFTP::CreateDir ( const char * dir )
{
if ( !CFTP::TryLogin ( ) )
{
curl_easy_cleanup ( Handle );
return 0;
}
char
info [ MAX_PATH + 5 ];
sprintf_s ( info, sizeof info, "MKD %s", dir );
curl_slist * slist = NULL;
slist = curl_slist_append ( slist, info );
if ( curl_easy_setopt ( Handle, CURLOPT_QUOTE, slist ) )
{
curl_easy_cleanup ( Handle );
return 0;
}
curl_slist_free_all ( slist );
res = curl_easy_perform ( Handle );
curl_easy_cleanup ( Handle );
if ( res )
return 0;
return 1;
}
|