問題描述
我在我的項目中使用 FluentFTP
lib 來通過 TLS 使用 FTP,但這里有些麻煩.
I have used FluentFTP
lib im my project to work with FTP via TLS, but some trouble here.
這段代碼運行良好:
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);
}
并創建了目錄.但在其他示例中,它效果不佳.
And directory were created. But in other examples it not working good.
第一個示例(日志文件 - https://pastebin.com/jNyZ3fmD):
First exmple (logfile - 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);
}
}
我有錯誤:
"將文件上傳到服務器時出錯.請參閱 InnerException 了解更多信息."IOException:身份驗證失敗,因為遠程方已關閉傳輸流
"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):
Trying to get file/dir-list from FTP using code below return nothing in console (logfile - 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);
}
}
用戶有權下載、創建和刪除文件.但是我只能在服務器上創建一個目錄.
The user has the privilege to download, create and delete files. But I can only make a dir on server.
推薦答案
好像是因為 FluenFTP 缺少 TLS 會話恢復支持:
https://github.com/robinrodricks/FluentFTP/issues/347
It seems to be due to a lack of TLS session resumption support in FluenFTP:
https://github.com/robinrodricks/FluentFTP/issues/347
如果您與服務器所有者確認,您將不得不切換到另一個 FTP 庫.對于類似的問題(對于隱式 TLS,當您使用顯式 TLS 時)請參閱:
在 C# 中使用 TLS 會話重用將文件上傳到隱式 FTPS 服務器
If you confirm that with the server owner, you will have to switch to another FTP library.
For a similar question (for an implicit TLS, while you are using an explicit TLS) see:
Upload file to implicit FTPS server in C# with TLS session reuse
或者要求所有者關閉會話恢復要求(盡管從安全角度來看這很糟糕).
Or ask the owner to turn off session resumption requirement (though that's bad from a security point of view).
有關該問題的更多參考,另請參閱可以使用 FileZilla 或 WinSCP 連接到 FTP,但不能使用 FtpWebRequest 或 FluentFTP.
For more references about the problem, see also Can connect to FTP using FileZilla or WinSCP, but not with FtpWebRequest or FluentFTP.
這篇關于“驗證失敗,因為遠程方已關閉傳輸流"使用 FluentFTP 通過 TLS/SSL 向/從 FTP 服務器傳輸數據時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!