当我试图连接到我的FTP服务器来用FluentFTP上传一个文件时,我得到以下信息:
根据验证过程,远程证书无效。
然而,FileZilla工作正常,没有错误或警告。
我做错什么了吗?如果服务器出了问题,我怎么能忽略这个错误?
这是我的密码:
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;
}
但我也不能让它起作用--我还是会犯同样的错误。
下面是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
发布于 2017-05-14 03:44:05
Client_ValidateCertificate
需要手动接受这样的证书:
private static void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
e.Accept = true;
}
然而,盲目地接受任何证书确实是个坏主意。最后我做了这样的事:
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)}");
}
}
https://stackoverflow.com/questions/43959141
复制相似问题