0

我无法使用 SharpSSH 建立安全的 FTP 连接。到目前为止,我一直在使用 DOS 命令行应用程序 MOVEit Freely 进行连接,并且连接正常:

C:\> ftps -user:ABC -password:123 xxx.xxx.xxx.mil

但是,当我尝试使用 SharpSSH 做同样的事情时,我收到一个错误,提示连接超时或服务器没有正确响应:

Dim sftp = New Tamir.SharpSsh.Sftp("xxx.xxx.xxx.mil", "ABC", "123")
sftp.Connect()

或者

Dim host = New Tamir.SharpSsh.SshStream("xxx.xxx.xxx.mil", "ABC", "123")

知道我可能做错了什么,或者我怎么能找出失败的地方?

请注意,我需要一个安全的 FTP 连接,因此 .NET 类不是一个选项。如果它们存在,我愿意尝试 SharpSSH 的替代品。

4

2 回答 2

2

您正在使用 Tamir.SharpSsh,它是一个 SSH 库。但是,您似乎正在连接到 FTPS(或 FTP/SSL)服务器。FTPS 是完全不同的协议,与 SFTP 或 SSH 没有任何共同之处。

我们网站上的以下页面讨论了 FTP、FTP/SSL、FTPS 和 SFTP 协议之间的区别:rebex.net/secure-ftp.net/

简要总结如下:

  • FTP 普通的、旧的、不安全的文件传输协议。通过网络传输明文密码。

  • FTPS - 通过 TLS/SSL 加密通道的 FTP。FTP 和 FTPS 的关系类似于 HTTP 和 HTTPS。

  • FTP/SSL - 与 FTPS 相同

  • SFTP - SSH 文件传输协议。与 FTP 没有任何共同之处(除了名称之外)。通过 SSH 加密通信通道运行。

  • 安全 FTP - 可以是 SFTP 或 FTPS :-(

你可以试试Rebex File Transfer Pack组件,它同时支持 SFTP 和 FTPS 协议(但与 SharpSSH 不同,它需要一些钱)。

与 FTP/SSL 服务器的连接如下所示:

' Create an instance of the Ftp class. 
Dim ftp As New Ftp()

' Connect securely using explicit SSL. 
' Use the third argument to specify additional SSL parameters. 
ftp.Connect(hostname, 21, Nothing, FtpSecurity.Explicit)

' Connection is protected now, we can log in safely. 
ftp.Login(username, password)
于 2009-05-27T23:55:58.873 回答
2

另一个不错的选择(也不是免费的)是edtFTPnet/PRO,这是一个稳定、成熟的库,它为 .NET 中的 FTPS(和 SFTP)提供全面支持。

这是一些用于连接的示例代码:

   SecureFTPConnection ftpConnection = new SecureFTPConnection();

   // setting server address and credentials
   ftpConnection.ServerAddress = "xxx.xxx.xxx.mil";
   ftpConnection.UserName = "ABC";
   ftpConnection.Password = "123";

   // select explicit FTPS
   ftpConnection.Protocol = FileTransferProtocol.FTPSExplicit;

   // switch off server validation (only do this when testing)
   ftpConnection.ServerValidation = SecureFTPServerValidationType.None;

   // connect to server
   ftpConnection.Connect();
于 2009-06-04T00:41:31.320 回答