FluentFTP:根据验证过程,远程证书无效 [英] FluentFTP: The remote certificate is invalid according to the validation procedure

查看:103
本文介绍了FluentFTP:根据验证过程,远程证书无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试连接到我的FTP服务器以使用FluentFTP上传文件时,我得到了:

When I try to connect to my FTP server to upload a file with FluentFTP I get this:

根据验证过程,远程证书无效.

The remote certificate is invalid according to the validation procedure.

但FileZilla可以正常工作,没有错误或警告.

Yet FileZilla works fine with no error or warnings.

我做错什么了吗,如果这实际上是服务器的问题,我该如何忽略该错误

Am I doing something wrong and if it's actually a problem with the server how can I ignore this error

这是我的代码:

var credentials = new NetworkCredential(Username, Password);
FtpClient client = new FtpClient(Host, credentials)
{
    Port = Port,
    EncryptionMode = FtpEncryptionMode.Explicit
};
client.DataConnectionEncryption = true;

client.Connect();
var result = client.UploadFileAsync(FilePathName, RemotePathName, AllowOverwrite ? FtpExists.Overwrite : FtpExists.Skip, CreateRemoteDirectory, token).GetAwaiter().GetResult();
client.Disconnect();

我还尝试添加事件 client.ValidateCertificate + = Client_ValidateCertificate;

private static void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    e.PolicyErrors = SslPolicyErrors.None;
}

但是我还是无法得到同样的错误.

but I couldn't get that to work either I still get the same error.

这是FileZilla的输出:

Here's the output from FileZilla:

Status: Selected port usually in use by a different protocol.
Status: Resolving address of xxxxxxxxxxxxxxxxxxxxxx
Status: Connecting to xxx.xxx.xxx.xxx:xx...
Status: Connection established, waiting for welcome message...
Status: Initializing TLS...
Status: Verifying certificate...
Status: TLS connection established.
Status: Logged in
Status: Retrieving directory listing of "xxxxxxxxxxxxx"...
Status: Directory listing of "xxxxxxxxxxxxx" successful

推荐答案

Client_ValidateCertificate 需要手动接受这样的证书:

Client_ValidateCertificate needs to manually accept the certificate like this:

private static void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    e.Accept = true;
}

但是,仅仅盲目接受任何证书确实是一个坏主意.我最终做了这样的事情:

However it's really a bad idea to just blindly accept any Certificate. I ended up doing something like this:

private void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    if (e.PolicyErrors == SslPolicyErrors.None || e.Certificate.GetRawCertDataString() == TrustedRawCertData)
    {
        e.Accept = true;
    }
    else
    {
        throw new Exception($"{e.PolicyErrors}{Environment.NewLine}{GetCertificateDetails(e.Certificate)}");
    }
}

这篇关于FluentFTP:根据验证过程,远程证书无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆