ComponentPro UltimateSftp

      Handle exceptions

      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.
      ScpException The exception that is thrown when an SCP 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.
      Scp client = new Scp();
      
      try
      {
          // Connect to the SCP server. 
          client.Connect("localhost");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          // ... 
       
          // Download remote file '/test.dat' to 'c:\test.dat' 
          client.DownloadFile("/test.dat", "c:\\test.dat");
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      catch (ScpException exc)
      {
          Console.WriteLine("An error occurred: Code: {0}, Message: {1}", exc.Status, exc.Message);
      
          if (client.State != RemoteFileSystemState.Disconnected)
              client.Disconnect();
      }