ComponentPro UltimateFtp

      FileOverwriteMode Enumeration

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Specifies actions to resolve file existing issue.

      Syntax

      public enum FileOverwriteMode

      Members

      NameDescription
      ConfirmRaise the TransferConfirm event to confirm next action on an existing file. By handling the TransferConfirm event, the program can let user decide whether to overwrite the existing files.
      SkipSkip existing files.
      OverwriteOverwrite existing files without confirmation.
      OverwriteOlderFilesOverwrite existing files without confirmation if they are older than source files. If the File System is SFTP or FTP, using this mode is not recommended because modification dates are often misreported by FTP and SFTP servers, making this mode unreliable. We strongly recommend to use the CustomCompare mode and set the Comparer property to a file comparer or develop a custom solution by handling the TransferConfirm event. Make sure your system time is synchronized with the destination file system/server. If the source or destination file system is IRemoteFileSystem and the time differs (e.g. different timezone), specify a timezone offset in the ServerTimeZoneOffset property.
      OverwriteNewerFilesOverwrite existing files without confirmation if they are newer than source files. If the File System is SFTP or FTP, using this mode is not recommended because modification dates are often misreported by FTP and SFTP servers, making this mode unreliable. We strongly recommend to use the CustomCompare mode and set the Comparer property to a file comparer or develop a custom solution by handling the TransferConfirm event. Make sure your system time is synchronized with the destination file system/server. If the source or destination file system is IRemoteFileSystem and the time differs (e.g. different timezone), specify a timezone offset in the ServerTimeZoneOffset property.
      OverwriteFilesWithDifferentLastModifiedTimeOverwrite existing files without confirmation if they are newer or older than source files. If the File System is SFTP or FTP, using this mode is not recommended because modification dates are often misreported by FTP and SFTP servers, making this mode unreliable. We strongly recommend to use the CustomCompare mode and set the Comparer property to a file comparer or develop a custom solution by handling the TransferConfirm event. Make sure your system time is synchronized with the destination file system/server. If the source or destination file system is IRemoteFileSystem and the time differs (e.g. different timezone), specify a timezone offset in the ServerTimeZoneOffset property.
      OverwriteFilesWithDifferentSizesOverwrite existing files with different sizes. The destination file will be overwritten without confirmation if it is different to the source file in length.
      OverwriteFilesWithDifferentChecksumsOverwrite existing files with different checksums. The destination file will be overwritten without confirmation if its checksum is different to the source file's.
      CustomCompareUse Comparer to compare source and destination files. If the return value of the Compare method indicate that the source and destination files are equal, the existing will be skipped; otherwise, it will be overwritten.
      ResumeFileTransferResume file transfer. Not available in file move mode. If the destination file size is less than the source file size, the component will resume file transfer. If there is no difference in file length, the destination file wont be overwritten. If the destination file size is greater than the source file size, the destination file will be overwritten.
      RenameUse a different name for an existing file. New name is generated from the current item according the pattern specified in RenamingPattern ("filename[number].extension" by default).
      Top

      Examples

      FTP Examples

      Shows how to use Download method to download files and directories on an FTP server. The download process is controlled with handlers of the TransferConfirm and Progress events.

      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("demo.componentpro.com");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          // ... 
       
          client.TransferConfirm += client_TransferConfirm;
          client.Progress += client_Progress;
      
          try 
          {
              TransferOptions opt = new TransferOptions("*.*", FileOverwriteMode.Confirm);
      
              // Get all directories, subdirectories, and files in remote folder '/myfolder' to 'c:\myfolder'. 
              client.Download("/myfolder", "c:\\myfolder", opt);
          }
          catch (Exception exc)
          {
              Console.WriteLine("Error: " + exc.Message);
          }
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      /// <summary> 
      /// This method is raised when user clicks on 'Cancel' button on the form. 
      /// </summary> 
      protected static void btnCancel_Click(object sender, EventArgs e)
      {
          // Cancel the download operation when user clicks on the button. 
          _client.Cancel();
      }
      
      static void client_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e)
      {
          // Show progress info. 
          Console.WriteLine("Current File: %{0} completed", e.Percentage);
          Console.WriteLine("Total: %{0} completed", e.TotalPercentage);
      
          switch (e.State)
          {
              case TransferState.StartDownloadingFile:
                  if (e.SourcePath.EndsWith(".exe"))
                  {
                      // Skip all .exe files 
                      e.Skip = true;
                  }
                  else if (e.SourcePath.StartsWith("/MyFolder"))
                  {
                      // Change the source file path if it starts with "/MyFolder" 
                      e.SourcePath = e.SourcePath.Replace("/MyFolder", "/MySecondFolder");
                  }
                  break;
          }
      }
      
      static void client_TransferConfirm(object sender, ComponentPro.IO.TransferConfirmEventArgs e)
      {
          if (e.Exception != null)
              Console.WriteLine("Error: " + e.Exception.Message);
      
          if (e.ConfirmReason == TransferConfirmReason.FileAlreadyExists)
          {
              // Skip the existing file. 
              e.NextAction = TransferConfirmNextActions.Skip;
          }
      
          Console.Write("Do you want to (r)etry or (s)kip?");
          string key = Console.ReadLine();
          if (key == "r")
              e.NextAction = TransferConfirmNextActions.Retry;
          else if (key == "s")
              e.NextAction = TransferConfirmNextActions.Skip;
          else 
              // Cancel the operation. 
              e.NextAction = TransferConfirmNextActions.Cancel;
      }

      SFTP Examples

      Shows how to use Upload methods to upload files. The system will skip existing files on the server.

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      public void DoUpload()
      {
          // Create a new class instance. 
          Sftp client = new Sftp();
      
          // Connect to the SFTP server. 
          client.Connect("demo.componentpro.com");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          // ... 
       
          client.TransferConfirm += client_TransferConfirm;
          client.Progress += client_Progress;
      
          try 
          {
              TransferOptions opt = new TransferOptions("*.*", FileOverwriteMode.Confirm);
      
              // Get all directories, subdirectories, and files in local folder 'c:\myfolder' to remote folder '/myfolder'. 
              client.Upload("c:\\myfolder", "/myfolder", opt);
          }
          catch (Exception exc)
          {
              Console.WriteLine("Error: " + exc.Message);
          }
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      void client_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e)
      {
          // Show progress info. 
          Console.WriteLine("Current File: %{0} completed", e.Percentage);
          Console.WriteLine("Total: %{0} completed", e.TotalPercentage);
      
          switch (e.State)
          {
              case TransferState.StartUploadingFile:
                  if (e.SourcePath.EndsWith(".exe"))
                  {
                      // Skip all .exe files 
                      e.Skip = true;  
                  }
                  else if (e.SourcePath.StartsWith(@"C:\MyFolder"))
                  {
                      // Change the source file path if it starts with "C:\MyFolder" 
                      e.SourcePath = e.SourcePath.Replace(@"C:\MyFolder", @"C:\MySecondFolder");
                  }
                  break;
          }
      }
      
      void client_TransferConfirm(object sender, ComponentPro.IO.TransferConfirmEventArgs e)
      {
          if (e.Exception != null)
              Console.WriteLine("Error: " + e.Exception.Message);
      
          if (e.ConfirmReason == TransferConfirmReason.FileAlreadyExists)
          {
              // Skip the existing file. 
              e.NextAction = TransferConfirmNextActions.Skip;
          }
      
          Console.Write("Do you want to (r)etry or (s)kip?");
          string key = Console.ReadLine();
          if (key == "r")
              e.NextAction = TransferConfirmNextActions.Retry;
          else if (key == "s")
              e.NextAction = TransferConfirmNextActions.Skip;
          else 
              // Cancel the operation. 
              e.NextAction = TransferConfirmNextActions.Cancel;
      }

      ZIP Examples

      Shows how to use AddFiles methods to upload files. The system will skip existing files on the server.

      using System;
      using ComponentPro.IO;
      using ComponentPro.Compression;
      
      ...
      
      private Zip _zip;
      public void DoUpload()
      {
          // Create a new instance. 
          Zip zip = new Zip();
          _zip = zip;
      
          // Create a new archive. 
          zip.Create("test.zip");
      
          // ... 
       
          zip.TransferConfirm += zip_TransferConfirm;
          zip.Progress += zip_Progress;
      
          try 
          {
              TransferOptions opt = new TransferOptions("*.*", FileOverwriteMode.Confirm);
      
              // Add all directories, subdirectories, and files in local folder 'c:\myfolder' to remote folder '/myfolder'. 
              zip.AddFiles("c:\\myfolder", "/myfolder", opt);
          }
          catch (Exception exc)
          {
              Console.WriteLine("Error: " + exc.Message);
          }
      
          // ... 
       
          // Close. 
          zip.Close();
      }
      
      /// <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 upload operation when user clicks on the button. 
          _zip.Cancel();
      }
      
      void zip_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e)
      {
          // Show progress info. 
          Console.WriteLine("Current File: %{0} completed", e.Percentage);
          Console.WriteLine("Total: %{0} completed", e.TotalPercentage);
      
          switch (e.State)
          {
              case TransferState.StartStoringFile:
                  if (e.SourcePath.EndsWith(".exe"))
                  {
                      // Skip all .exe files 
                      e.Skip = true;
                  }
                  else if (e.SourcePath.StartsWith(@"C:\MyFolder"))
                  {
                      // Change the source file path if it starts with "C:\MyFolder" 
                      e.SourcePath = e.SourcePath.Replace(@"C:\MyFolder", @"C:\MySecondFolder");
                  }
                  break;
          }
      }
      
      void zip_TransferConfirm(object sender, ComponentPro.IO.TransferConfirmEventArgs e)
      {
          if (e.Exception != null)
              Console.WriteLine("Error: " + e.Exception.Message);
      
          if (e.ConfirmReason == TransferConfirmReason.FileAlreadyExists)
          {
              // Skip the existing file. 
              e.NextAction = TransferConfirmNextActions.Skip;
          }
      
          Console.Write("Do you want to (r)etry or (s)kip?");
          string key = Console.ReadLine();
          if (key == "r")
              e.NextAction = TransferConfirmNextActions.Retry;
          else if (key == "s")
              e.NextAction = TransferConfirmNextActions.Skip;
          else 
              // Cancel the operation. 
              e.NextAction = TransferConfirmNextActions.Cancel;
      }

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.FileSystem.CF (in ComponentPro.FileSystem.CF.dll)

      .NET Framework.NET Framework

      Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
      Assembly: ComponentPro.FileSystem (in ComponentPro.FileSystem.dll)

      Portable Class Library for Windows Phone 8.1 and Windows 8.1 Store AppsPortable Class Library for Windows Phone 8.1 and Windows 8.1 Store Apps

      Supported version: 4.6.x and later
      Assembly: ComponentPro.FileSystem.WinPcl (in ComponentPro.FileSystem.WinPcl.dll)

      Universal Windows Platform (includes Windows 10 Mobile, Windows 10 Store Apps and Windows 10 IoT)Universal Windows Platform (includes Windows 10 Mobile, Windows 10 Store Apps and Windows 10 IoT)

      Supported version: 4.6.x and later
      Assembly: ComponentPro.FileSystem.Uwp (in ComponentPro.FileSystem.Uwp.dll)

      Xamarin AndroidXamarin Android

      Supported version: 2.3 and later
      Assembly: ComponentPro.FileSystem.Android (in ComponentPro.FileSystem.Android.dll)

      Xamarin MacXamarin Mac

      Supported version: 2.0.x and later
      Assembly: ComponentPro.FileSystem.Mac (in ComponentPro.FileSystem.Mac.dll)

      Xamarin iOSXamarin iOS

      Supported version: 5.1.x and later
      Assembly: ComponentPro.FileSystem.iOS (in ComponentPro.FileSystem.iOS.dll)

      See Also