C# .NET FtpWebRequest 是否支持隐式 (FTPS) 和显式 (FTPES)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1842186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?
提问by PortageMonkey
I am being asked to support implicit and explicit FTPS (also known as FTPES). We are currently using the .NET FtpWebRequest
. Does the FtpWebRequest
support both types of FTPES, and what is the difference?
我被要求支持隐式和显式 FTPS(也称为 FTPES)。我们目前正在使用 .NET FtpWebRequest
. 是否FtpWebRequest
支持两种类型的FTPES,有什么区别?
Thanks
谢谢
采纳答案by Martin Vobr
as far as I know the current (.NET 2.0 and 3.5) version of FtpWebRequest supports Explicit SSL only.
据我所知,当前(.NET 2.0 和 3.5)版本的 FtpWebRequest 仅支持显式 SSL。
Actually, .NET 2.0 does not currently support implicit SSL, only explicit. We will consider adding this for a future release.
JonCole - MSFTModerator at MSDN forum post
实际上,.NET 2.0 目前不支持隐式 SSL,只支持显式。我们会考虑在未来的版本中添加这个。
JonCole - MSDN 论坛帖子中的MSFTModerator
If you need to use both Implict and Explicit TLS/SSL you have to try one of third-party FTP/SSL components. Following code uses our Rebex FTP/SSLand is taken from the tutorial page.
如果您需要同时使用隐式和显式 TLS/SSL,您必须尝试使用第三方 FTP/SSL 组件之一。以下代码使用我们的Rebex FTP/SSL,取自教程页面。
Explicit TLS/SSL
显式 TLS/SSL
Client connects to FTP server in a usual non-protected way, usually to port 21 was assigned to FTP protocol. When it is desired to protect the connection using SSL, an SSL negotiation is initialized, control connection is secured and all following communication is being protected.
客户端以通常的非保护方式连接到 FTP 服务器,通常将端口 21 分配给 FTP 协议。当需要使用 SSL 保护连接时,会初始化 SSL 协商,保护控制连接并保护所有后续通信。
// Create an instance of the Ftp class.
Ftp ftp = new Ftp();
// Connect securely using explicit SSL.
// Use the third argument to specify additional SSL parameters.
ftp.Connect(hostname, 21, null, FtpSecurity.Explicit);
// Connection is protected now, we can log in safely.
ftp.Login(username, password);
Explicit protection means that it is possible to secure the connection at any moment. If you don't know whether you will need the protection on not at the connection time, you might want to connect using the ordinary unencrypted FTP protocol and secure the connection later.
显式保护意味着可以随时保护连接。如果您不知道在连接时是否需要保护,您可能希望使用普通的未加密 FTP 协议进行连接,并在以后保护连接。
Ftp ftp = new Ftp();
// Connect to the server with no protection.
ftp.Connect(hostname, 21);
// Upgrade connection to SSL.
// This method also accepts an argument to specify SSL parameters.
ftp.Secure();
// Connection is protected now, we can log in safely.
ftp.Login(username, password);
Implicit SSL protection of the FTP session
FTP 会话的隐式 SSL 保护
FTPS protocol was originally assigned a separate port by the IANA. Upon connection to this port, an SSL negotiation starts immediately and the control connection is secured. All data connections are also secured implicitly in the same way. This is similar to the approach used by HTTPS.
FTPS 协议最初由 IANA 分配了一个单独的端口。连接到此端口后,SSL 协商立即开始,控制连接将受到保护。所有数据连接也以相同的方式隐式保护。这类似于 HTTPS 使用的方法。
This approach is not favored by the IETF and is deprecated. It is supported by Rebex FTP/SSL for interoperability with older servers, but it is strongly recommended to use the explicit protection instead whenever possible.
这种方法不受 IETF 的青睐,已被弃用。Rebex FTP/SSL 支持与旧服务器的互操作性,但强烈建议尽可能使用显式保护。
Ftp ftp = new Ftp();
// Connect securely using implicit SSL.
// Use the third argument to specify additional SSL parameters.
ftp.Connect(hostname, 990, null, FtpSecurity.Implicit);
// Connection is protected now, we can log in safely.
ftp.Login(username, password);
You may download the component at rebex.net/ftp-ssl.net/
您可以在rebex.net/ftp-ssl.net/下载该组件
回答by Martin Vobr
I have used Alex FTPS Client earlier. May be you should look to http://ftps.codeplex.com/.
我之前使用过 Alex FTPS Client。可能你应该看看http://ftps.codeplex.com/。
回答by Bruce Blackshaw
edtFTPnet/PROis an FTP client library that also supports FTPS implicit and explicit modes. It's simply a matter of specifying the right protocol:
edtFTPnet/PRO是一个 FTP 客户端库,它也支持 FTPS 隐式和显式模式。这只是指定正确协议的问题:
SecureFTPConnection conn = new SecureFTPConnection();
conn.Protocol = FileTransferProtocol.FTPSImplicit;
// set remote host, user, pwd etc ...
// now connect
conn.Connect();
The same component supports SFTP also.
相同的组件也支持 SFTP。
And yes, I am one of the developers of this component (and of edtFTPnet, the free, open source .NET FTP client).
是的,我是该组件(以及edtFTPnet,免费的开源 .NET FTP 客户端)的开发人员之一。
回答by Pawel Lesnikowski
You can also try Ftp.dll FTP/FTPS client.
你也可以试试Ftp.dll FTP/FTPS 客户端。
It supports implicitand explicitSSL connections. Here's the implicit sample:
它支持隐式和显式SSL 连接。这是隐式示例:
using(Ftp ftp = new Ftp())
{
ftp.ConnectSSL("ftp.server.com");
ftp.Login("user", "password");
ftp.ChangeFolder("uploads");
ftp.UploadFile("report.txt", @"c:\report.txt");
ftp.Close();
}
Please note that this is commercial product and I'm the author of this component.
请注意,这是商业产品,我是该组件的作者。
回答by Martin Prikryl
.NET Framework/FtpWebRequest
supports only explicit TLS/SSL encryption. It does not support implicit TLS/SSL encryption.
.NET Framework/FtpWebRequest
仅支持显式 TLS/SSL 加密。它不支持隐式 TLS/SSL 加密。
I believe it's unlikely it ever will. The FTP implementation of .NET frameworks uses only standardized features of the protocol. The implicit TLS/SSL encryption was never standardized. It was introduced only as a temporary mechanism to allow using seamless encryption with FTP clients that did not support encryption. In general, there's no reason to use implicit TLS/SSL encryption. An FTP server that supports implicit TLS/SSL encryption only, is broken, imo. Note that RFC 2228 [FTP Security Extensions]was introduced over 20 years ago!
我相信它永远不可能。.NET 框架的 FTP 实现仅使用协议的标准化功能。隐式 TLS/SSL 加密从未标准化。它仅作为一种临时机制引入,以允许对不支持加密的 FTP 客户端使用无缝加密。通常,没有理由使用隐式 TLS/SSL 加密。仅支持隐式 TLS/SSL 加密的 FTP 服务器已损坏,imo。请注意,RFC 2228 [FTP 安全扩展]是在 20 多年前引入的!
Anyway, if you need to use the implicit TLS/SSL encryption, you have to use a 3rd party FTP library.
无论如何,如果您需要使用隐式 TLS/SSL 加密,则必须使用 3rd 方 FTP 库。
With WinSCP .NET assembly, it's easy:
使用WinSCP .NET 程序集,这很容易:
// Set up session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
UserName = "username",
Password = "password",
FtpSecure = FtpSecure.Implicit,
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
}
You can have WinSCP GUI generate a C# FTP code template, like the one above, for you.
您可以让WinSCP GUI 为您生成一个 C# FTP 代码模板,就像上面的那样。
(I'm the author of WinSCP)
(我是 WinSCP 的作者)