简体   繁体   English

使用WinSCP .NET程序集通过FTPS(安全)发送文件

[英]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)? 使用FTPS(安全)将文件发送到具有WinSCP(.NET程序集)的服务器需要什么?

I've been looking at their documentation and am not really clear on certain aspects like TlsHostCertificateFingerprint or TlsClientCertificatePath . 我一直在看他们的文档,但在某些方面(例如TlsHostCertificateFingerprintTlsClientCertificatePath并不清楚。

I've been able to send out files via FTP and SFTP with no problem, but this whole thing just eludes me. 我已经能够通过FTP和SFTP毫无问题地发送文件了,但是这整个事情使我难以理解。

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 : 如果您有用于FTP的代码, SessionOptions.FtpSecure连接到性能良好的FTPS(基于TLS / SSL的FTP)服务器, 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. 如果您的服务器证书不是由受信任的机构签名的,则仅需要TlsHostCertificateFingerprint

The TlsClientCertificatePath is needed only, if your server requires authenticating with a client certificate. 如果您的服务器需要使用客户端证书进行身份验证,则仅需要TlsClientCertificatePath


Easiest is to configure your session in WinSCP GUI and have it generate a code template for you. 最简单的方法是在WinSCP GUI中配置会话,并使其为您生成代码模板 That's actually how I got the above code. 这实际上就是我获得上述代码的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM