This example demonstrates the 8 following steps for listing files with the GetFolderContents method:
-
Specify the FTP server's address
-
Specify the username to login
-
Specify the password for the username
-
Connect to the FTP server
-
Obtain the directory listing object
-
Disconnect from the FTP server
-
Process the listed items
-
Perform error handling
NOTE: The code below considers that you are using the #import compiler directive (included in the code below)
VC++ ATL |
Copy Code |
#import "XceedFtp.dll" named_guids no_namespace
int main(int argc, char* argv[]) { CoInitialize( NULL );
try // for step (8) { 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(); // step (4)
printf( "Successfully connected to the server.\nObtaining the contents of the current remote folder.\n" );
try // for step (8) { IXceedFtpFolderItemsPtr piFolderItems; // for step (7) IXceedFtpFolderItemPtr piItem; // for step (7) _bstr_t sName;
// step (5) piFolderItems = piXceedFtp->GetFolderContents( _bstr_t( "" ), fcfCollection );
printf( "Successfully obtained the contents of the remote folder.\n");
piXceedFtp->Disconnect();
// step (7) for( long lIndex = 1; lIndex <= piFolderItems->Count; lIndex++ ) { piItem = piFolderItems->Item[ &_variant_t( lIndex ) ]; sName = piItem->GetItemName();
printf( "%S\n", ( const WCHAR* )sName ); } } catch( const _com_error& xErr ) // step (8) { printf( "An error occurred: %s\n", ( const WCHAR* ) xErr.Description() ); } catch( ... ) { printf( "An unexpected error occurred" ); } } catch( const _com_error& xErr ) // step (8) { printf( "An error occurred : %s\n", ( const WCHAR* ) xErr.Description() ); } catch( ... ) { printf( "An unexpected error occurred" ); }
CoUninitialize(); return 0; } |