我正在尝试使用FluentFTP通过连接端口990 (TLS)的FTPS下载文件。
但是代码无法建立连接并显示异常,因为“根据验证过程,远程证书无效”。
当我手动使用FTP FTP工具时,FTP服务器连接正常(显示为通过FileZilla (隐式)连接)
FtpClient fclient = new FtpClient(hostname, username, password);
fclient.EncryptionMode = FtpEncryptionMode.Implicit;
fclient.SslProtocols = SslProtocols.Tls12; //Also tried with TLS1 and TLS
fclient.Port = 990;
fclient.Connect();
发布于 2021-06-29 22:47:36
试试这个(取自FluentFTP的ConnectFTPSCertificate.cs示例)。最重要的部分是回调OnValidateCertificate
。
public static async Task ConnectFTPSCertificateAsync() {
var token = new CancellationToken();
using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
conn.EncryptionMode = FtpEncryptionMode.Explicit;
conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
await conn.ConnectAsync(token);
}
}
private static void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
if (e.PolicyErrors == System.Net.Security.SslPolicyErrors.None) {
e.Accept = true;
}
else {
// add logic to test if certificate is valid here
// lookup the "Certificate" and "Chain" properties
e.Accept = false;
}
}
发布于 2021-06-29 22:28:29
我也遇到过同样的问题。请注意,fluentFTP只支持外部接口,而不是隐式接口。我也尝试过ftpWebRequest,但没有成功。尝试使用winSCP。
https://stackoverflow.com/questions/52321147
复制相似问题