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

4

本文介绍了使用 WinSCP .NET 程序集通过 FTPS(安全)发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

使用 FTPS(安全)将文件发送到带有 WinSCP(.NET 程序集)的服务器需要什么?

What is required to send out files to a server with WinSCP (.NET assembly) using FTPS (Secure)?

我一直在查看他们的文档,但对 TlsHostCertificateFingerprintTlsClientCertificatePath 等某些方面并不是很清楚.

I've been looking at their documentation and am not really clear on certain aspects like TlsHostCertificateFingerprint or TlsClientCertificatePath.

我已经能够毫无问题地通过 FTP 和 SFTP 发送文件,但这整件事让我无法理解.

I've been able to send out files via FTP and SFTP with no problem, but this whole thing just eludes me.

推荐答案

如果你有 FTP 的代码,你只需要添加一个连接到一个表现良好的 FTPS (FTP over TLS/SSL) 服务器就是设置SessionOptions.FtpSecure:

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
}

<小时>

TlsHostCertificateFingerprint 仅在您的服务器证书未由受信任的机构签署时才需要.


The TlsHostCertificateFingerprint is needed only, if your server certificate is not signed by a trusted authority.

TlsClientCertificatePath 仅在您的服务器需要使用客户端证书进行身份验证时才需要.

The TlsClientCertificatePath is needed only, if your server requires authenticating with a client certificate.

最简单的方法是在 WinSCP GUI 中配置您的会话 并拥有它为您生成代码模板.这就是我得到上述代码的方式.

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.

这篇关于使用 WinSCP .NET 程序集通过 FTPS(安全)发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14