【问题标题】:FTP Connection issue- using FluentFTP for port 990 -TLSFTP 连接问题 - 将 FluentFTP 用于端口 990 -TLS
【发布时间】:2018-09-13 20:11:42
【问题描述】:

我正在尝试使用 FluentFTP 通过端口 990 (TLS) 的 FTPS 连接下载文件。

但代码无法建立连接并显示异常为“根据验证程序,远程证书无效。”

当我手动使用 FileZilla FTP 工具时,FTP 服务器连接正常(显示为通过 ftps over TLS 连接(隐式)

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();

【问题讨论】:

  • 您可能手动让 Filezilla 接受证书。如果您尝试连接新的 FTP 客户端,例如 WinSCP,会怎样?它会在没有任何关于证书的提示的情况下连接吗?
  • stackoverflow.com/questions/19327840/… 如问题所示,您可能会破解ServerCertificateValidationCallback。如果您检查他们的文档/源代码,FluentFTP 可能有自己的证书验证处理程序。

标签: c# .net ftp fluentftp


【解决方案1】:

试试这个(取自 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;
    }
}

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。 注意fluentFTP只支持外部接口,不支持隐式 我也试过 ftpWebRequest 没有成功。 尝试使用 winSCP。

    【讨论】:

    • 什么是“外部接口”?你不是说explicit(相对于implicit)吗?虽然 FluentFTP 支持显式和隐式(FtpWebRequest 不支持 implicit.
    猜你喜欢
    • 1970-01-01
    • 2018-02-12
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多