连接到SFTP服务器时使用SharpSSH验证指纹

时间:2015-02-27 12:24:05

标签: ssh sftp public-key sharpssh rsa-key-fingerprint

我正在使用Tamir.SharpSSHSFTP代码中建立.NET个连接。我有服务器的主机,端口,用户名,密码和服务器的指纹。

我可以在没有指纹的情况下连接到服务器。在建立连接之前,有没有办法让我的指纹与服务器匹配?

以下是我的C#连接代码:

string _ftpURL = "ftp.com"; //Host URL or address of the SFTP server
string _UserName = "Login_Id";      //User Name of the SFTP server
string _Password = "12345";   //Password of the SFTP server
int _Port = 22;                  //Port No of the SFTP server (if any)
string _ftpDirectory = "ReceivedFiles"; //The directory in SFTP server where the files will be uploaded
string LocalDirectory = "D:\\FilePuller"; //Local directory from where the files will be uploaded

ArrayList UploadedFiles = new ArrayList();

Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password);

oSftp.Connect(_Port);

在连接到SFTP服务器之前,我是否可以添加服务器指纹检查?

1 个答案:

答案 0 :(得分:0)

SharpSSH非常愚蠢,默认情况下不会验证主机密钥。

您必须重新实施SshBase.ConnectSession,不要将StrictHostKeyChecking设置为no

  • 然后使用JSch.getHostKeyRepository().add()配置预期的主机密钥(或实现HostKeyRepository接口)。
  • 或实施UserInfo界面,尤其是promptYesNo方法。
相关问题