问题
What is required to send out files to a server with WinSCP (.NET assembly) using FTPS (Secure)?
I've been looking at their documentation and am not really clear on certain aspects like TlsHostCertificateFingerprint
or TlsClientCertificatePath
.
I've been able to send out files via FTP and SFTP with no problem, but this whole thing just eludes me.
回答1:
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
}
The TlsHostCertificateFingerprint
is needed only, if your server certificate is not signed by a trusted authority.
The TlsClientCertificatePath
is needed only, if your server requires authenticating with a client certificate.
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.
来源:https://stackoverflow.com/questions/43766939/sending-files-over-ftps-secure-using-winscp-net-assembly