FtpClient.ValidateCertificate Event

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Event is fired to validate SSL certificates. If this event is not handled and there are errors validating the certificate the connection will be aborted.

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public event FtpSslValidation ValidateCertificate
Visual Basic
Public Event ValidateCertificate As FtpSslValidation
Visual C++
public:
virtual  event FtpSslValidation^ ValidateCertificate {
	void add (FtpSslValidation^ value);
	void remove (FtpSslValidation^ value);
}

Value

Type: System.Net.FtpClient..::..FtpSslValidation

Implements

IFtpClient..::..ValidateCertificate

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;

namespace Examples {
    public static class ValidateCertificateExample {
        public static void ValidateCertificate() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.EncryptionMode = FtpEncryptionMode.Explicit;
                conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
                conn.Connect();
            }
        }

        static void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
            if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None) {
                // invalid cert, do you want to accept it?
                // e.Accept = true;
            }
        }
    }
}

See Also