ComponentPro UltimateSftp

      Display progress while transferring data

      Language Filter: AllSend comments on this topic to ComponentPro

      When the file to transfer is big and your application may take time to transfer, you may wish to show the progress of the transfer to the user. The Ultimate SFTP component provides progress notification through the Progress event. The Progress event is raised periodically while data transfer is in progress, making accessible necessary data to display progress information, such as the size of the file and the number of transferred bytes.

      The example below shows how to use the Progress event to show progress information:

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      static void Main()
          string server = "localhost";
          string userName = "administrator";
          string password = "sfb@123";
          // Create a new Scp instance. 
          Scp client = new Scp();
          client.Progress += client_Progress;
          Console.WriteLine("Connecting to SCP server: {0}...", server);
          // Connect to the SCP server. 
          Console.WriteLine("Logging in as: {0}...", userName);
          // Authenticate. 
          client.Authenticate(userName, password);
          Console.WriteLine("Uploading ''...");
          // Upload file "c:\". 
          client.UploadFile("c:\\", "");
          // And download file "". 
          Console.WriteLine("\r\nDownloading ''...");
          client.DownloadFile("", "");
          // Disconnect. 
      static void client_Progress(object sender, FileSystemProgressEventArgs e)
          if (e.State == TransferState.Uploading)
              Console.Write("\rUploaded: {0} bytes ({1}% completed) - {2}", e.BytesTransferred, e.Percentage, e.DestinationPath);
          else if (e.State == TransferState.Downloading)
              Console.Write("\rDownloaded: {0} bytes - {2}", e.BytesTransferred, e.SourcePath);