ComponentPro UltimateFtp

      Download a remote file to a local file or stream

      Language Filter: AllSend comments on this topic to ComponentPro

      Download data to a file

      To download a single file, use the DownloadFile method. The first parameter is the path to the remote file and the second parameter is the local path.

      // Create a new class instance.
      Ftp client = new Ftp();
      
      // Connect to the FTP server.
      client.Connect("localhost");
      
      // Authenticate.
      client.Authenticate("test", "test");
      
      // ... 
       
      // Download remote file '/test.dat' to 'c:\test.dat'
      client.DownloadFile("/test.dat", "c:\\test.dat");
      
      // ... 
       
      // Disconnect.
      client.Disconnect();
      
      You can set download speed limits by using the MaxDownloadSpeed property

      Download data to a stream

      To download data from the remote file to a stream, simply use the DownloadFile method which has two parameters, or another version of the DownloadFile method for transferring data starting from a specific stream position. The first parameter is the remote file path and the second one is the data stream object. It returns the number of bytes transferred.

      // Create a new class instance.
      Ftp client = new Ftp();
      
      // Connect to the FTP server.
      client.Connect("localhost");
      
      // Authenticate.
      client.Authenticate("test", "test");
      
      // ... 
       
      // Create new file
      FileStream fo = new FileStream("c:\\file.dat", FileMode.Create);
      
      // Download remote file '/test.dat' to 'c:\test.dat'
      client.DownloadFile("/test.dat", fo);
      
      fo.Close();
      
      // ... 
       
      // Disconnect.
      client.Disconnect();