ComponentPro UltimateSftp

      Handle errors

      Language Filter: AllSend comments on this topic to ComponentPro

      Exceptions thrown by the component and its dependencies can easily be caught by using try catch block. The table below lists all exceptions that can be caught when using the component: 

      Exception Description
      UltimateLicenseException The exception that is thrown when an error occurs while checking the license.
      SftpException The exception that is thrown when an SFTP error occurs.
      ProxySocketException The exception that is thrown when a proxy error or socket error occurs.

       

      The example below shows how to handle exceptions:

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      // Create a new class instance.
      Sftp client = new Sftp();
      
      try
      {
          // Connect to the SFTP server. 
          client.Connect("myserver");
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // ... 
       
          // Create 'myFolder' folder. 
          client.CreateDirectory("/myFolder");
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      catch (SftpException exc)
      {
          if (client.State == RemoteFileSystemState.Connected ||
              client.State == RemoteFileSystemState.Ready)
          {
              client.Disconnect();
          }
      
          Console.WriteLine("An error occurred: " + exc.Message);
      }