使用WinSCP .NET程序集通过FTPS(安全)发送文件 [英] Sending files over FTPS (secure) using WinSCP .NET assembly
问题描述
使用FTPS(安全)将文件发送到具有WinSCP(.NET程序集)的服务器需要什么?
What is required to send out files to a server with WinSCP (.NET assembly) using FTPS (Secure)?
我一直在看他们的文档,在某些方面(例如TlsHostCertificateFingerprint
或TlsClientCertificatePath
)并不清楚.
I've been looking at their documentation and am not really clear on certain aspects like TlsHostCertificateFingerprint
or TlsClientCertificatePath
.
我已经能够通过FTP和SFTP毫无问题地发送文件,但这整个事情使我难以理解.
I've been able to send out files via FTP and SFTP with no problem, but this whole thing just eludes me.
推荐答案
如果您有FTP的代码,则只需将设置为 SessionOptions.FtpSecure
:
If you have a code for FTP, all you need to add to connect to a well-behaved FTPS (FTP over TLS/SSL) server is to set the SessionOptions.FtpSecure
:
// Set up session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "ftp.example.com",
UserName = "username",
Password = "password",
// Enable FTPS in explicit mode, aka FTPES
FtpSecure = FtpSecure.Explicit,
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
}
如果您的服务器证书未由受信任的机构签名,则仅需要TlsHostCertificateFingerprint
.
仅当服务器需要使用客户端证书进行身份验证时,才需要TlsClientCertificatePath
.
The TlsClientCertificatePath
is needed only, if your server requires authenticating with a client certificate.
最简单的方法是在WinSCP GUI中配置会话,并将其
Easiest is to configure your session in WinSCP GUI and have it generate a code template for you. That's actually how I got the above code.
这篇关于使用WinSCP .NET程序集通过FTPS(安全)发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!