连接到SFTP服务器时使用SharpSSH指纹 [英] Veryfing fingerprints using SharpSSH while connecting to SFTP Server

查看:345
本文介绍了连接到SFTP服务器时使用SharpSSH指纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Tamir.SharpSSH to make SFTP connections in my .NET code. I have servers' host, port, username, password and servers' fingerprint.

我无需指纹即可连接到服务器.建立连接之前,有什么方法可以将我与服务器的指纹相匹配?

I am able to connect to the server without the fingerprint. Is there any way to match the fingerprint that I have with the servers' before making the connection?

以下是我的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服务器之前添加对服务器指纹的检查吗?

Is there anyway I can add a check for Server's fingerprint before connecting to the SFTP Server?

推荐答案

SharpSSH非常愚蠢,无法默认验证主机密钥.

The SharpSSH is stupid enough not to verify the host keys by default.

您将不得不重新实现SshBase.ConnectSession而不是将StrictHostKeyChecking设置为no.

You would have to re-implement SshBase.ConnectSession not to set StrictHostKeyChecking to no.

  • 然后使用JSch.getHostKeyRepository().add()配置所需的主机密钥(或实现HostKeyRepository接口).
  • 或实现UserInfo接口,尤其是promptYesNo方法.
  • And then use JSch.getHostKeyRepository().add() to configure expected host key (or implement HostKeyRepository interface).
  • Or implement UserInfo interface, particularly the promptYesNo method.

这篇关于连接到SFTP服务器时使用SharpSSH指纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆