Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

c# - Sending files over FTPS (secure) using WinSCP .NET assembly

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...