問題描述
我正在嘗試使用 TLS 協(xié)議通過 ftps 將文件上傳到 FileZilla 服務(wù)器.服務(wù)器上的 20 和 21 端口已關(guān)閉.我設(shè)法連接到服務(wù)器的唯一方法是使用 FluentFTP,但由于某些 FileZilla 服務(wù)器錯(cuò)誤,我無法上傳文件.
有什么辦法可以避免違反安全級(jí)別?如果沒有,是否還有其他免費(fèi)庫支持使用 TLS/SSL 上傳文件?我也試過這個(gè),但沒有用.
https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl
謝謝.
你可以使用 WinSCP .NET 程序集.
它支持隱式 TLS(端口 990).并且使用 OpenSSL TLS 實(shí)現(xiàn)(不是 .NET Framework),所以應(yīng)該沒有 FluentFTP 的問題.它對(duì)我來說絕對(duì)適用于 FileZilla FTP 服務(wù)器,即使打開了會(huì)話恢復(fù)要求.
SessionOptions sessionOptions = new SessionOptions{協(xié)議 = Protocol.Ftp,主機(jī)名 = ftp.example.com",用戶名 = 用戶名",密碼=密碼",F(xiàn)tpSecure = FtpSecure.Implicit,TlsHostCertificateFingerprint = "xx:xx:xx:...",};使用(會(huì)話會(huì)話 = 新會(huì)話()){session.Open(sessionOptions);session.PutFiles(localPath, remotePath).Check();}
(我是 WinSCP 的作者)
有關(guān)該問題的更多參考,另請(qǐng)參閱可以使用 FileZilla 或 WinSCP 連接到 FTP,但不能使用 FtpWebRequest 或 FluentFTP.
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
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;
}
}
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
Thanks.
You can use WinSCP .NET assembly.
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();
}
(I'm the author of WinSCP)
For more references about the problem, see also Can connect to FTP using FileZilla or WinSCP, but not with FtpWebRequest or FluentFTP.
這篇關(guān)于使用 TLS 會(huì)話重用將文件上傳到 C# 中的隱式 FTPS 服務(wù)器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!