Xceed FTP Library Documentation
Example topics / Receiving Files ATL example
In This Topic
    Receiving Files ATL example
    In This Topic

    This example demonstrates the 7 following steps for receiving files:  

    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. Receive files 
    6. Disconnect from the FTP server 
    7. 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;
    }