使用 TLS 会话重用将文件上传到 C# 中的隐式 FTPS 服务器
Upload file to implicit FTPS server in C# with TLS session reuse
我正在尝试通过 TLS 协议通过 ftps 将文件上传到 FileZilla 服务器。服务器端口 20 和 21 已关闭。我设法连接到服务器的唯一方法是使用 FluentFTP,但由于某些 FileZilla 服务器错误,我无法上传文件。
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;
}
}
有没有不违反安全级别的解决方法?如果没有,是否还有其他免费库支持使用 TLS/SSL 上传文件?我也试过这个但是没有用。
https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl
谢谢。
您可以使用 WinSCP .NET assembly.
它支持隐式 TLS(端口 990)。并且使用 OpenSSL TLS 实现(不是 .NET Framework),所以它不应该有 FluentFTP 有的问题。它绝对适用于 FileZilla FTP 服务器,即使会话恢复要求已打开。
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();
}
(我是WinSCP的作者)
有关该问题的更多参考资料,另请参阅 。
我正在尝试通过 TLS 协议通过 ftps 将文件上传到 FileZilla 服务器。服务器端口 20 和 21 已关闭。我设法连接到服务器的唯一方法是使用 FluentFTP,但由于某些 FileZilla 服务器错误,我无法上传文件。
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;
}
}
有没有不违反安全级别的解决方法?如果没有,是否还有其他免费库支持使用 TLS/SSL 上传文件?我也试过这个但是没有用。
https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl
谢谢。
您可以使用 WinSCP .NET assembly.
它支持隐式 TLS(端口 990)。并且使用 OpenSSL TLS 实现(不是 .NET Framework),所以它不应该有 FluentFTP 有的问题。它绝对适用于 FileZilla FTP 服务器,即使会话恢复要求已打开。
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();
}
(我是WinSCP的作者)
有关该问题的更多参考资料,另请参阅