使用TLS会话重用将文件上传到C#中的隐式FTPS服务器 [英] Upload file to implicit FTPS server in C# with TLS session reuse

查看:279
本文介绍了使用TLS会话重用将文件上传到C#中的隐式FTPS服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过协议TLS通过ftp将文件上传到FileZilla服务器.在服务器上,端口20和21已关闭.我设法连接到服务器的唯一方法是使用FluentFTP,但由于FileZilla服务器的某些错误,我无法上传文件.

I'm trying to upload file to FileZilla server through ftps by protocol TLS. On the server port 20 and 21 is closed. The only way how I managed to connect to server is by using FluentFTP but I couldn't upload file because of some FileZilla server bug.

https://github.com/robinrodricks/FluentFTP/issues/335
https://forum.filezilla-project.org/viewtopic.php?t= 51601

https://github.com/robinrodricks/FluentFTP/issues/335
https://forum.filezilla-project.org/viewtopic.php?t=51601

public static void UploadTest(
    string pathUploadFile, string addressIP, int port, string location,
    string userName, string password)
{
    FtpClient ftp;

    Console.WriteLine("Configuring FTP to Connect to {0}", addressIP);
    ftp = new FtpClient(addressIP, port, new NetworkCredential(userName, password));
    ftp.ConnectTimeout = 600000;
    ftp.ReadTimeout = 60000;
    ftp.EncryptionMode = FtpEncryptionMode.Implicit;
    ftp.SslProtocols = SslProtocols.Default | SslProtocols.Tls11 | SslProtocols.Tls12;
    ftp.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
    ftp.Connect();
    // upload a file
    ftp.UploadFile(pathUploadFile, location);

    Console.WriteLine("Connected to {0}", addressIP);
    ftp.Disconnect();

    void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
    {
        // add logic to test if certificate is valid here
        e.Accept = true;
    }
}

在没有违反安全级别的情况下有什么办法吗?如果没有,是否有其他免费库支持使用TLS/SSL上传文件?我也试过了,但是没用.
https://docs.microsoft.com/zh-我们/dotnet/api/system.net.ftpwebrequest.enablessl

Is there any way around without a violating security level? If not is there any other free library which support uploading files with TLS/SSL? I also tried this but it didn't work.
https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl

谢谢.

推荐答案

您可以使用 WinSCP .NET程序集.

它支持隐式TLS(端口990).并且使用OpenSSL TLS实现(而不是.NET Framework),因此它不应该具有FluentFTP所具有的问题.即使打开了会话恢复要求,它也对FileZilla FTP服务器绝对适合我.

It supports implicit TLS (port 990). And uses OpenSSL TLS implementation (not .NET Framework), so it should not have the problem that FluentFTP has. It definitely works for me against FileZilla FTP server, even with session resumption requirement turned on.

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = "ftp.example.com",
    UserName = "username",
    Password = "password",
    FtpSecure = FtpSecure.Implicit,
    TlsHostCertificateFingerprint = "xx:xx:xx:...",
};

using (Session session = new Session())
{
    session.Open(sessionOptions);

    session.PutFiles(localPath, remotePath).Check();
}

(我是WinSCP的作者)

这篇关于使用TLS会话重用将文件上传到C#中的隐式FTPS服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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