ComponentPro UltimateFtp

      Upload data from a file or stream

      Language Filter: AllSend comments on this topic to ComponentPro

      Upload data from a file

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

      // Create a new class instance.
      Ftp client = new Ftp();
      
      // Connect to the FTP server.
      client.Connect("localhost");
      
      // Authenticate.
      client.Authenticate("test", "test");
      
      // ... 
       
      // Upload local file 'c:\test.dat' to '/test.dat'.
      client.UploadFile("c:\\test.dat", "/test.dat");
      
      // ... 
       
      // Disconnect.
      client.Disconnect();
      
      You can set upload speed limits by using the MaxUploadSpeed property

      Upload data from a stream

      It is very easy to upload data from a local file or a stream. To upload data from a stream to the remote FTP server, simply use the UploadFile method which has two parameters, or another version of the UploadFile method for transferring data starting from a specific stream position. The first parameter is the data stream object and the second one is the remote file path. 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");
      
      // ...
      
      FileStream fi = new FileStream("c:\\test.dat", FileMode.Open);
      
      // Upload data from a stream to '/test.dat'.
      client.UploadFile(fi, "/test.dat");
      
      fi.Close();
      
      // ... 
       
      // Disconnect.
      client.Disconnect();