.NET FtpWebRequest是否支持隐式(FTPS)和显式(FTPES)?

时间:2009-12-03 19:09:12

标签: c# .net ftp ftpwebrequest ftps

我被要求支持隐式和显式FTPS(也称为FTPES)。我们目前正在使用.NET FtpWebRequestFtpWebRequest是否支持两种类型的FTPES,有什么区别?

由于

5 个答案:

答案 0 :(得分:17)

据我所知,当前(.NET 2.0和3.5)版本的FtpWebRequest仅支持Explicit SSL。

  

实际上,.NET 2.0目前还没有   支持隐式SSL,只显式。   我们会考虑添加这个   未来发布。

     

JonCole - 位于MSDN forum post的MSFTModerator

如果您需要同时使用Implict和Explicit TLS / SSL,则必须尝试使用​​第三方FTP / SSL组件之一。以下代码使用我们的Rebex FTP/SSL,并取自tutorial page

明确的TLS / SSL

客户端以通常的非保护方式连接到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);

明确保护意味着可以随时保护连接。如果您不知道在连接时是否需要保护,则可能需要使用普通的未加密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);

FTP会话的隐式SSL保护

最初,IANA为FTPS协议分配了一个单独的端口。连接到此端口后,将立即启动SSL协商并确保控制连接。所有数据连接也以相同方式隐式保护。这类似于HTTPS使用的方法。

这种方法不受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);

您可以在rebex.net/ftp-ssl.net/

下载该组件

答案 1 :(得分:12)

我之前使用过Alex FTPS客户端。你应该看看http://ftps.codeplex.com/

答案 2 :(得分:4)

.NET Framework / FtpWebRequest仅支持显式TLS / SSL加密。它不支持隐式TLS / SSL加密。

我相信它不太可能。 .NET框架的FTP实现仅使用协议的标准化功能。隐式TLS / SSL加密从未标准化。它仅作为临时机制引入,允许对不支持加密的FTP客户端使用无缝加密。通常,没有理由使用隐式TLS / SSL加密。仅支持隐式TLS / SSL加密的FTP服务器已损坏,imo。请注意,RFC 2228 [FTP Security Extensions]是在20多年前推出的!

无论如何,如果您需要使用隐式TLS / SSL加密,则必须使用第三方FTP库。

使用WinSCP .NET assembly,很容易:

// 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
}

您可以拥有WinSCP GUI generate a C# FTP code template,就像上面的那样。

(我是WinSCP的作者)

答案 3 :(得分:1)

您也可以尝试Ftp.dll FTP/FTPS client

它支持隐式显式 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();
}

请注意,这是商业产品,我是该组件的作者。

答案 4 :(得分:0)

edtFTPnet/PRO是一个FTP客户端库,它也支持FTPS隐式和显式模式。这只是指定正确协议的问题:

 SecureFTPConnection conn = new SecureFTPConnection();
 conn.Protocol = FileTransferProtocol.FTPSImplicit;

 // set remote host, user, pwd etc ...

 // now connect
 conn.Connect();

同样的组件也支持SFTP。

是的,我是这个组件的开发人员之一(以及免费的开源.NET FTP客户端edtFTPnet)。