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

痴心易碎 提交于 2020-02-28 09:32:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!