2009-05-26 115 views
0

我無法使用SharpSSH進行安全的FTP連接。到現在爲止我一直在使用DOS命令行應用程序MOVEit自由地進行連接,並罰款接口:無法通過FTP連接SharpSSH

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。

回答

2

您正在使用Tamir.SharpSsh,它是一個SSH庫。但是,它看起來像連接到FTPS(或FTP/SSL)服務器。 FTPS是完全不同的協議,與SFTP和SSH沒有任何共同之處。

我們網站上的以下頁面討論FTP,FTP/SSL,FTPS和SFTP協議之間的區別:rebex.net/secure-ftp.net/

小結如下:

  • FTP平原,舊的,不安全的文件傳輸協議。通過網絡傳輸明文密碼。

  • FTPS - FTP over TLS/SSL加密 頻道。 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) 
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();