ComponentPro UltimateFtp

      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.
      FtpException The exception that is thrown when an FTP 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 Ftp instance.
      Ftp client = new Ftp();
      
      try
      {
          // Connect to the FTP server. 
          client.Connect("myserver");
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // ... 
       
          // Create 'myFolder' folder. 
          client.CreateDirectory("/myFolder");
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      catch (FtpException exc)
      {
          if (client.IsConnected)
          {
              client.Disconnect();
          }
      
          Console.WriteLine("An error occurred: " + exc.Message);
      }