/// <summary> /// Automatic FTP and FTPS connection negotiation. /// This method tries every possible combination of the FTP connection properties, and connects to the first successful profile. /// Returns the FtpProfile if the connection succeeded, or null if it failed. /// </summary> public FtpProfile AutoConnect() { LogFunc("AutoConnect"); // detect the first available connection profile var results = AutoDetect(); if (results.Count > 0) { var profile = results[0]; // if we are using SSL, set a basic server acceptance function if (profile.Encryption != FtpEncryptionMode.None) { ValidateCertificate += new FtpSslValidation(delegate(FtpClient c, FtpSslValidationEventArgs e) { if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None) { e.Accept = false; } else { e.Accept = true; } }); } // connect to the first found profile Connect(profile); // return the working profile return(profile); } return(null); }
private void SetDefaultCertificateValidation(FtpProfile profile) { if (profile.Encryption != FtpEncryptionMode.None) { ValidateCertificate += new FtpSslValidation(delegate(FtpClient c, FtpSslValidationEventArgs e) { if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None) { e.Accept = false; } else { e.Accept = true; } }); } }