我正在尝试通过协议TLS通过ftp将文件上传到FileZilla服务器。在服务器上,端口20和21已关闭。我设法连接到服务器的唯一方法是使用FluentFTP,但是由于FileZilla服务器的错误,我无法上传文件。
https://github.com/robinrodricks/FluentFTP/issues/335https://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;
}
}
在没有违反安全级别的情况下有什么办法吗?如果没有,是否有其他免费库支持使用ssl上传文件?我也尝试过,但是没有用。https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.enablessl?view=netframework-4.8
谢谢。
如果使用的是.NET框架(不是.NET核心),则可以使用WinSCP .NET assembly。
它支持隐式TLS(端口990)。并且使用OpenSSL TLS实现(不是.NET框架),因此它不应该具有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();
}