ComponentPro UltimateFtp

      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;
      private static void Main()
          // Create a new Ftp instance. 
          Ftp client = new Ftp();
          // Connect to the FTP server. 
          // Authenticate. 
          client.Authenticate("test", "test");
              // Register an event handler. 
              client.Progress += client_Progress;
              // Upload file "c:\". 
              client.UploadFile("c:\\", "");
          catch (FtpException exc)
              Console.WriteLine("Exception: " + exc.Message);
          // Disconnect. 
      private static 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)
              ((Ftp) sender).Cancel();