ComponentPro UltimateSftp

      Abort an operation

      Language Filter: AllSend comments on this topic to ComponentPro

      To abort any file transfer in progress you can either call the Cancel method or simply close the connection by calling the Disconnect or DisconnectAsync method.

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      [STAThread]
      static void Main()
      {
          const string server = "myserver";
          const string userName = "username";
          const string password = "password";
      
          // Create a new Scp instance. 
          Scp client = new Scp();
      
          client.Progress += client_Progress;
      
          // Connect to the SFTP server. 
          client.Connect(server);
      
          // Authenticate. 
          client.Authenticate(userName, password);
      
          try 
          {
              // Upload file "c:\test.zip". 
              client.UploadFile("c:\\test.zip", "test.zip");
          }
          catch (ScpException exc)
          {
              Console.WriteLine("Exception: " + exc.Message);
          }
      
          // Disconnect. 
          client.Disconnect();
      }
      
      static void client_Progress(object sender, FileSystemProgressEventArgs e)
      {
          // Abort the uploading operation if the bytes transferred is greater than or equal to 1024. 
          if (e.State == TransferState.Uploading && e.BytesTransferred >= 1024)
          {
              ((Scp)sender).Cancel();
          }
      }