ComponentPro UltimateSftp

      TransferState Enumeration

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Specifies the state of a file transfer.

      Syntax

      public enum TransferState

      Members

      NameDescription
      NoneNo state spefcified.
      BuildingDirectoryStructureBuilding directory structure. This state is available when the library is retrieving information of directory structure before transferring or processing the directory contents. When the BuildDirectoryTree option of a TransferOptions or MultiFileOperationOptions instance is set to true, the library retrieves the directory hierarchy before transferring or processing the directory contents.
      StartCopyingFileThe current file is about to be copied.
      StartUploadingFileA file from another file system or content from a stream is about to upload/copy to the remote server - usually FTP, SFTP, or SCP. This field equals to StartStoringFile. When the transfer state is StartUploadingFile, you can change source file path, destination file path, or skip uploading file in the Progress event handler.
      StartStoringFileA file from another file system or content from a stream is about to added to this file system - Zip, RealTimeZip, Tar, Tgz, or Gzip. This field equals to StartUploadingFile. When the transfer state is StartStoringFile, you can change source file path, destination file path, or skip storing file in the Progress event handler.
      StartDownloadingFileA remote file is about to be downloaded to another file system or a stream of data. When the transfer state is StartDownloadingFile, you can change source file path, destination file path, or skip downloading file in the Progress event handler.
      StartExtractingFileZIP File system is about to extract a file to another file system or a stream of data. This field equals to StartDownloadingFile. When the transfer state is StartExtractingFile, you can change source file path, destination file path, or skip extracting file in the Progress event handler.
      StartComparingFileThe current file is about to be compared with another one in a multi-file transfer or synchronization process. This state is available when file comparer, specified in Comparer of the TransferOptions class or Comparer of the QuickSyncOptions class, is an instance of a class that inherits the IoFileComparer class - FileContentComparer or FileChecksumComparer. A folder synchronization is initiated by calling the QuickSynchronize or QuickSynchronizeAsync method.
      MovingItemA file or directory is being moved while moving files on the same system with MoveFiles set to true. When the transfer state is MovingItem, you can change source file path and destination file path or skip moving the item in the Progress event handler.
      CopyingDirectoryA directory is being copied. You can skip copying the directory by setting the Skip property to true or cancel the whole process by calling the Cancel methods.
      CreatingDirectoryA directory is being created. You cannot change source file path and destination file path. You can only skip creating an empty directory with this transfer state.
      SettingFilePermissionPermissions of a file or directory are about to be set.
      SettingFileAttributeAttributes of a file or directory are about to be set.
      CopyingThe current file is being copied.
      UploadingA file or content from a stream is being uploaded to the remote server - usually FTP, SFTP, or SCP. This field equals to Storing.
      StoringA file or content from a stream is being stored/added to this file system - usually Zip, RealTimeZip, Tar, Tgz, or Gzip. This field equals to Uploading.
      DownloadingA remote file is being downloaded to another file system or a stream of data. This field equals to Copying.
      ExtractingZIP file system is extracting a file to another file system or a stream of data. This field equals to Copying and Downloading.
      ComparingThe current file is being compared with another one. This state is available when a file comparer, specified in Comparer of the TransferOptions class or Comparer of the QuickSyncOptions class, is an instance of a class that inherits the IoFileComparer class - usually FileContentComparer or FileChecksumComparer. If the transfer state is Comparing, the file is being compared with another one in a multi-file transfer or synchronization process. A folder synchronization is initiated by calling the QuickSynchronize or QuickSynchronizeAsync method.
      DeletingFileThe current file is being deleted. When the transfer state is DeletingFile, you can change source file path or skip deleting file in the Progress event handler.
      DeletingDirectoryThe current directory is being deleted. When the transfer state is DeletingDirectory, you can change the source file path or skip deleting file in the Progress event handler.
      DirectoryStructureBuiltDirectory structure has been built and the file system is ready to process (transfer, delete, or set attributes) files and directories. When the BuildDirectoryTree option of a TransferOptions or MultiFileOperationOptions instance is set to true, the library retrieves the directory hierarchy before transferring or processing the directory contents.
      FileCopiedThe current file copy operation has completed.
      FileUploadedUpload completed. This field equals to FileStored.
      FileStoredFile has been stored. This field equals to FileUploaded.
      FileDownloadedDownload completed. This field equals to FileCopied.
      FileExtractedArchive item has been extracted successfullly. This field equals to FileDownloaded and FileCopied.
      FileComparedThe current file has been compared in a multi-file transfer or synchronization process. This state is available when file comparer, specified in Comparer of the TransferOptions class or Comparer of the QuickSyncOptions class, is an instance of a class that inherits the IoFileComparer class - FileContentComparer or FileChecksumComparer. A folder synchronization is initiated by calling the QuickSynchronize or QuickSynchronizeAsync method.
      DirectoryCreatedAn empty directory has been created successfully or the destination directory already exists.
      FileDeletedA file has been deleted successfully.
      DirectoryDeletedA directory has been deleted successfully.
      ItemMovedA file or directory has been moved while moving files on the same system with MoveFiles set to true.
      FilePermissionSetFile or directory permissions have been set.
      FileAttributeSetFile or directory attributes have been set.
      DirectoryStructureRetrievalFailedFailed to retrieve the directory hierarchy or user has canceled the operation.
      FileCopyFailedFailed to copy file.
      FileUploadFailedFailed to store the file or user has canceled the operation.
      FileStoreFailedFailed to store the file or user has canceled the operation.
      FileDownloadFailedFailed to download the file or user has canceled the operation.
      FileExtractFailedFailed to extract the file or user has canceled the operation.
      FileDeletionFailedFailed to delete the file or user has canceled the operation.
      DirectoryDeletionFailedFailed to delete the directory or user has canceled the operation.
      DirectoryCreationFailedFailed to create the directory or user has canceled the operation.
      ItemMoveFailedFailed to move the item or user has canceled the operation.
      SetFilePermissionFailedFailed to set file or directory permissions.
      SetFileAttributeFailedFailed to set file or directory attributes.
      ItemSkippedThe operation on the current file or directory has been skipped.
      MultiFileOperationCompletedIndicates a multi-file operation has completed.
      CanceledThe transfer of the item was canceled.
      Top

      Examples

      FTP Examples

      Shows how to abort an operation using the Cancel method.

      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. 
          client.Connect("demo.componentpro.com");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          try 
          {
              // Register an event handler. 
              client.Progress += client_Progress;
      
              // Upload file "c:\test.zip". 
              client.UploadFile("c:\\test.zip", "test.zip");
          }
          catch (FtpException exc)
          {
              Console.WriteLine("Exception: " + exc.Message);
          }
      
          // Disconnect. 
          client.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();
          }
      }

      SFTP Examples

      Shows how to abort an operation using the Cancel method.

      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. 
          client.Connect("demo.componentpro.com");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          try 
          {
              // Register an event handler. 
              client.Progress += client_Progress;
      
              // Upload file "c:\test.zip". 
              client.UploadFile("c:\\test.zip", "test.zip");
          }
          catch (SftpException exc)
          {
              Console.WriteLine("Exception: " + exc.Message);
          }
      
          // Disconnect. 
          client.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)
          {
              ((Sftp)sender).Cancel();
          }
      }

      FTP Examples

      Shows how to use the Delete method to delete .tmp files in a directory.

      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();
      }

      SFTP Examples

      Shows how to use DeleteDirectory method to delete .tmp files in a directory. Skip file that its name contains "my file" text.

      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      public void DoDelete()
      {
          // Create a new class instance. 
          Sftp client = new Sftp();
      
          // Connect to the SFTP server. 
          client.Connect("192.168.126.128", 2222);
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          client.Progress += client_Progress;
      
          // ... 
       
          // Delete *.tmp files 
          client.Delete("/", true, "*.tmp");
          
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      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;
          }
      }

      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;
      }

      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