This example demonstrates the 7 following steps for receiving files:
-
Specify the FTP server's address
-
Specify the username to login
-
Specify the password for the username
-
Connect to the FTP server
-
Receive files
-
Disconnect from the FTP server
-
Perform error handling
NOTE: The code below considers that you are using the #import compiler directive (included in the code below)
ATL |
Copy Code |
#import "XceedFtp.dll" named_guids no_namespace
int main(int argc, char* argv[]) { CoInitialize( NULL );
try // step (7) { IXceedFtpPtr piXceedFtp( CLSID_XceedFtp ); piXceedFtp->License( _bstr_t( L"your license key ) );
piXceedFtp->ServerAddress = "ftp.cdrom.com"; // step (1) piXceedFtp->UserName = "anonymous"; // step (2) piXceedFtp->Password = "guest"; // step (3)
piXceedFtp->Connect(); printf( "Successfully connected to server. Starting download.\n" );
try // step (7) { piXceedFtp->ReceiveFile( "UPLOADS.TXT", 0, "c:\\Temp\\cdrom_Uploads.txt" ); // step (5)
// Use the ReceiveMultipleFiles method if you want to use wildcards // to receive more than one file at a time.
printf( "Successfully downloaded the file.\n" ); } catch( const _com_error& xErr ) { printf("Download error: %s\n", ( const WCHAR* ) xErr.Description() ); }
piXceedFtp->Disconnect(); // step (6) } catch( const _com_error& xErr ) { printf( "Connect error: %s\n", ( const WCHAR* ) xErr.Description() ); } catch( ... ) { printf( "An unknown error occurred.\n" ); }
CoUninitialize(); return 0; }
|