【问题标题】:How to download files from FTPS in C#如何在 C# 中从 FTPS 下载文件
【发布时间】:2019-07-12 16:23:34
【问题描述】:

我们的 IT 部门给了我一个 FTPS 的凭据,我可以使用 FileZilla 访问它

但我还需要使用我正在开发的应用程序来访问 FTPS,以使该过程自动化。提供给我的信息是,

这是一个基于 TLS/SSL 的 FTP

IP:xxx.xxx.xx.xx

端口:990

用户名:用户名.ftp

密码: password123

在阅读了有关 WinSCP on stack 及其文档的一些帖子后,我仍然无法使用我的应用程序访问 ftps。到目前为止我的代码..

        SessionOptions sessionOp = new SessionOptions()
        {
            FtpSecure = FtpSecure.Implicit,
            Protocol = Protocol.Ftp,
            HostName = IP,              
            UserName = userName,
            Password = password,
        };

        sessionOp.AddRawSettings("ProxyMethod", "3");
        sessionOp.AddRawSettings("ProxyPort", "990");

        using (Session session = new Session())
        {
            session.Open(sessionOp);
            var list = session.ListDirectory(dir);
            Console.WriteLine(list);
        }

我得到的错误是 WinSCP 的“连接失败”

如何访问此 FTPS?

【问题讨论】:

    标签: c# .net ftp winscp-net


    【解决方案1】:

    您所做的是将 HTTP 代理端口配置为 990。相反,您应该配置 FTPS 端口。

    SessionOptions sessionOp = new SessionOptions()
    {
        FtpSecure = FtpSecure.Implicit,
        Protocol = Protocol.Ftp,
        HostName = IP,              
        UserName = userName,
        Password = password,
        PortNumber = 990
    };
    

    并删除行

    sessionOp.AddRawSettings("ProxyMethod", "3");
    sessionOp.AddRawSettings("ProxyPort", "990");
    

    另外,考虑到该库与 GUI 相关,我建议使用 the WinSCP GUI 而不是 FileZilla。

    【讨论】:

    • 好的,现在我收到新的错误,这意味着进步?它说,对等证书被拒绝
    • @Adas:查找 TlsClientCertificatePath 或 TlsHostCertificateFingerprint 或 GiveUpSecurityAndAcceptAnyTlsHostCertificate
    • 无需设置PortNumber = 990 - 这是FtpSecure.Implicit 的默认值 + 对于"peer certificate denied" 使用TlsHostCertificateFingerprintGiveUpSecurityAndAcceptAnyTlsHostCertificate 不安全并且@ 987654329@ 用于客户端而不是服务器证书)+ 通常,在 WinSCP GUI 中设置连接并拥有generate a code template for you 更容易。要获取TlsHostCertificateFingerprint 的值,您需要在生成代码之前登录。 +1
    • @MartinPrikryl 这是一个不错的功能,现在可以使用 tls 证书方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 1970-01-01
    相关资源
    最近更新 更多