我在我的项目中使用了 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/