Upload file to implicit FTPS server in C# with TLS session reuse(使用 TLS 会话重用将文件上传到 C# 中的隐式 FTPS 服务器)
问题描述
我正在尝试使用 TLS 协议通过 ftps 将文件上传到 FileZilla 服务器.服务器上的 20 和 21 端口已关闭.我设法连接到服务器的唯一方法是使用 FluentFTP,但由于某些 FileZilla 服务器错误,我无法上传文件.
有什么办法可以避免违反安全级别?如果没有,是否还有其他免费库支持使用 TLS/SSL 上传文件?我也试过这个,但没有用.
https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl
谢谢.
你可以使用 WinSCP .NET 程序集.
它支持隐式 TLS(端口 990).并且使用 OpenSSL TLS 实现(不是 .NET Framework),所以应该没有 FluentFTP 的问题.它对我来说绝对适用于 FileZilla FTP 服务器,即使打开了会话恢复要求.
SessionOptions sessionOptions = new SessionOptions{协议 = Protocol.Ftp,主机名 = ftp.example.com",用户名 = 用户名",密码=密码",FtpSecure = FtpSecure.Implicit,TlsHostCertificateFingerprint = "xx:xx:xx:...",};使用(会话会话 = 新会话()){session.Open(sessionOptions);session.PutFiles(localPath, remotePath).Check();}
(我是 WinSCP 的作者)
有关该问题的更多参考,另请参阅可以使用 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.
这篇关于使用 TLS 会话重用将文件上传到 C# 中的隐式 FTPS 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 TLS 会话重用将文件上传到 C# 中的隐式 FTP


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01