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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…