ComponentPro UltimateSftp

      Cancel an operation

      Language Filter: AllSend comments on this topic to ComponentPro

      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. 
          // Authenticate. 
          client.Authenticate("test", "test");
              // Register an event handler. 
              client.Progress += client_Progress;
              // Upload file "c:\". 
              client.UploadFile("c:\\", "");
          catch (SftpException exc)
              Console.WriteLine("Exception: " + exc.Message);
          // 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)