When the file to transfer is big, or the transfer speed is slow, you can let the user know that your app is transferring files by updating a progress bar. The Ultimate SFTP component provides progress notification through the Progress event. The 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 bytes transferred.
The following example shows you how to handle the Progress event to show progress information while transferring a file:
using System; using ComponentPro.IO; using ComponentPro.Net; ... static void Main() { // Create a new Sftp instance. Sftp client = new Sftp(); // Connect to the SFTP server. client.Connect("demo.componentpro.com"); // Authenticate. client.Authenticate("test", "test"); // Register an event handler. client.Progress += client_Progress; // Upload file "c:\test.zip". client.UploadFile("c:\\test.zip", "test.zip"); // And download file "test.zip". client.DownloadFile("test.zip", "test_download.zip"); // Disconnect. client.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 ({1}% completed) - {2}", e.BytesTransferred, e.Percentage, e.SourcePath); }