c# - 使用 FluentFTP 通过 TLS/SSL 与 FTP 服务器传输时为 "Authentication failed because the remote party has closed the transport stream"

标签 c# .net ssl ftp fluentftp

我在我的项目中使用了 FluentFTP lib 通过 TLS 使用 FTP,但这里遇到了一些问题。

这段代码工作正常:

using (var conn = new FtpClient("adress", "user", "password"))
{
    conn.EncryptionMode = FtpEncryptionMode.Explicit;
    conn.ValidateAnyCertificate = true;
    conn.Connect();

    conn.CreateDirectory("/test/path/that/should/be/created", true);
}

目录已创建。但在其他示例中它效果不佳。

第一个示例(日志文件 - https://pastebin.com/jNyZ3fmD ):

public static void DownloadFile()
{
    using (var conn = new FtpClient("adress", "user", "password"))
    {
        conn.EncryptionMode = FtpEncryptionMode.Explicit;
        conn.ValidateAnyCertificate = true;
            conn.Connect();

        conn.DownloadFile("localPath", "ftpPath", FtpLocalExists.Overwrite, FtpVerify.Retry);

    }
}

我有错误:

"Error while uploading the file to the server. See InnerException for more info." IOException: Authentication failed because the remote party has closed the transport stream

尝试使用下面的代码从 FTP 获取文件/目录列表在控制台中不会返回任何内容(日志文件 - https://pastebin.com/V8AiLs8k ):

using (var conn = new FtpClient("adress", "user", "password"))
{
    //conn.Connect();
    conn.EncryptionMode = FtpEncryptionMode.Explicit;
    conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
    conn.Connect();

    // get a recursive listing of the files & folders in a specific folder
    foreach (var item in conn.GetListing())
    {
        switch (item.Type)
        {

            case FtpFileSystemObjectType.Directory:

                Console.WriteLine("Directory!  " + item.FullName);
                Console.WriteLine("Modified date:  " + conn.GetModifiedTime(item.FullName));

                break;

            case FtpFileSystemObjectType.File:

                Console.WriteLine("File!  " + item.FullName);
                Console.WriteLine("File size:  " + conn.GetFileSize(item.FullName));
                Console.WriteLine("Modified date:  " + conn.GetModifiedTime(item.FullName));
                Console.WriteLine("Chmod:  " + conn.GetChmod(item.FullName));

                break;

            case FtpFileSystemObjectType.Link:
                break;
        }
        Console.WriteLine(item);
    }

}

用户具有下载、创建和删除文件的权限。但我只能在服务器上创建一个目录。

最佳答案

这似乎是由于 FluenFTP 中缺乏 TLS session 恢复支持造成的:
https://github.com/robinrodricks/FluentFTP/issues/347

如果您与服务器所有者确认,您将必须切换到另一个 FTP 库。 对于类似的问题(对于隐式 TLS,当您使用显式 TLS 时)请参阅:
Upload file to implicit FTPS server in C# with TLS session reuse

或者要求所有者关闭 session 恢复要求(尽管从安全角度来看这很糟糕)。

有关该问题的更多引用,另请参阅 Can connect to FTP using FileZilla or WinSCP, but not with FtpWebRequest or FluentFTP .

关于c# - 使用 FluentFTP 通过 TLS/SSL 与 FTP 服务器传输时为 "Authentication failed because the remote party has closed the transport stream",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61068219/

相关文章:

iOS - 以编程方式信任 CA(证书颁发机构)

c# - 我如何在winform中用位图替换光标

c# - Nullable<T>.Equals 方法实现是否错误?

c# - 使用c#加密数据并使用openssl api解密数据,为什么解密数据末尾有很多垃圾填充?

c# - XAML 绑定(bind)到 ViewModel 中的控件

ssl - Amazon S3 数据完整性 MD5 与 SSL/TLS

c# - 如何将千位分隔符添加到可能包含 float 的字符串值

c# - 查询数据库中的每条记录比使用 LINQ 更快

.net - httplistener 在端口 80 上不起作用?

php - 使用无证书的 --ssl 使用 PHP PDO 连接到 MySQL/MariaDB