To abort a file transfer that is still in progress, you can either call the Cancel method or close the connection by calling the Disconnect or DisconnectAsync method.
The following code snippet shows how to use it.
using System; using ComponentPro.IO; using ComponentPro.Net; ... public void DoAbort() { // Create a new Sftp instance. Sftp client = new Sftp(); // Connect to the SFTP server. client.Connect("demo.componentpro.com"); // Authenticate. client.Authenticate("test", "test"); try { // Register an event handler. client.Progress += client_Progress; // Upload file "c:\test.zip". client.UploadFile("c:\\test.zip", "test.zip"); } catch (SftpException exc) { Console.WriteLine("Exception: " + exc.Message); } // Disconnect. client.Disconnect(); } void client_Progress(object sender, FileSystemProgressEventArgs e) { // Abort the uploading operation if the bytes transferred is greater than or equal to 500Kb. if (e.State == TransferState.Uploading && e.BytesTransferred >= 1024 * 500) { ((Sftp)sender).Cancel(); } }