ComponentPro UltimateFtp

      CertificateRequired Event

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Occurs when a client certificate is required by the FTP server, or the one provided was not accepted.

      Syntax

      public event EventHandler<TEventArgs> CertificateRequired

      Examples

      Show how to handle the CertificateRequired event.

      using System;
      using System.Security.Cryptography.X509Certificates;
      using ComponentPro.Net;
      
      ...
      
      static void Main()
      {
          // Create a new instance of the Ftp class. 
          Ftp client = new Ftp();
      
          client.CertificateRequired += client_CertificateRequired;
      
          // Connect to the FTP server. 
          client.Connect("myserver", 21, SslSecurityMode.Explicit);
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // Do something here... 
          client.DownloadFile("/my remote file.dat", "my local file");
      
          // Disconnect. 
          client.Disconnect();
      }
      
      static void client_CertificateRequired(object sender, ComponentPro.Security.CertificateRequiredEventArgs e)
      {
          // Load certificates from the local machine. 
          X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser);
          my.Open(OpenFlags.ReadOnly);
      
          // Retrieve a list of available certificates. 
          X509Certificate2Collection certs = my.Certificates;
      
          // If no certificate found, return. 
          if (certs.Count == 0)
          {
              e.Certificates = null;
              return;
          }
      
          // Show all certificates. 
          Console.WriteLine("Select certificate:");
          for (int i = 0; i <= certs.Count; i++)
          {
              if (i == 0)
              {
                  Console.WriteLine(string.Format("{0}. [Nothing, skip this step]", i));
                  continue;
              }
      
              Console.WriteLine(string.Format("{0}. {1}", i, certs[i - 1].SubjectName.Name));
          }
      
          // And ask user to choose an appropriate certificate. 
          while (true)
          {
              Console.Write(string.Format("Select certificate [0 - {0}]: ", certs.Count));
      
              int certIndex;
      
              try 
              {
                  certIndex = int.Parse(Console.ReadLine());
              }
              catch 
              {
                  Console.WriteLine("ERROR: Wrong certificate index input!");
                  continue;
              }
      
              if (certIndex > 0 && certIndex <= certs.Count)
              {
                  e.Certificates = new X509Certificate2Collection(certs[certIndex]);
                  return;
              }
      
              if (certIndex == 0)
                  break;
      
              Console.WriteLine(string.Format("ERROR: You must enter number between 0 and {0}.", certs.Count));
          }
      }

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.Ftp.CF (in ComponentPro.Ftp.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.Ftp (in ComponentPro.Ftp.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.Ftp.WinPcl (in ComponentPro.Ftp.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.Ftp.Uwp (in ComponentPro.Ftp.Uwp.dll)

      Xamarin AndroidXamarin Android

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

      Xamarin MacXamarin Mac

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

      Xamarin iOSXamarin iOS

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

      See Also