Xceed FTP Library Documentation
getting a remote folder's contents (C++ ATL example)
Example topics > getting a remote folder's contents (C++ ATL example)

This example demonstrates the 8 following steps for listing files with the GetFolderContents method:  

  1. Specify the FTP server's address 
  2. Specify the username to login 
  3. Specify the password for the username 
  4. Connect to the FTP server 
  5. Obtain the directory listing object 
  6. Disconnect from the FTP server 
  7. Process the listed items 
  8. 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; 
}