连接到SFTP服务器时使用SharpSSH指纹 [英] Veryfing fingerprints using SharpSSH while connecting to SFTP Server
问题描述
我正在使用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 implementHostKeyRepository
interface). - Or implement
UserInfo
interface, particularly thepromptYesNo
method.
这篇关于连接到SFTP服务器时使用SharpSSH指纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!