ComponentPro UltimateFtp

      Control multi-file deletion process

      Language Filter: AllSend comments on this topic to ComponentPro

      The Progress event of the Ftp class gives you the ease of controlling files to delete. To decide whether a file should be deleted, just handle the Progress event and set the Skip property of the FileSystemProgressEventArgs class to true. The following example illustrates how to do that:

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      private static Ftp _client;
      static void Main()
      {
          // Create a new class instance. 
          Ftp client = new Ftp();
          _client = client;
      
          // Connect to the FTP server. 
          client.Connect("192.168.126.128", 2222);
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          client.Progress += client_Progress;
      
          // ... 
       
          // Delete *.tmp files 
          client.Delete("/", false, true, "*.tmp");
          
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      static void client_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e)
      {
          if (e.State == TransferState.DeletingFile)
          {
              // Skip file that its name contains "my file" text. 
              if (e.SourcePath.IndexOf("my file") != -1)
                  e.Skip = true;
          }
      }
      
      /// <summary> 
      /// This method is raised when user clicks on 'Cancel' button on the form. 
      /// </summary> 
      protected void btnCancel_Click(object sender, EventArgs e)
      {
          // Cancel the deleting operation when user clicks on the button. 
          _client.Cancel();
      }