使用sharpSSH连接到sftp服务器时删除手动接受

时间:2015-03-04 12:49:06

标签: c# sftp sharpssh

一个小问题..我使用sharpSSH连接到SFTP服务器,并将“StrictHostKeyChecking”设置为“yes”。但是,每当我第一次尝试连接到新的SFTP服务器时,它会询问我是否要信任特定的服务器指纹。有没有办法可以跳过这一步并按程序接受它,因为我希望与这段代码进行最少的用户交互?另外,我不想将“strictHostKeyChecking”设置为“no”。有没有解决方法。我正在考虑手动在Known_hosts文件中添加指纹,但我认为我不能这样做,因为指纹以加密格式存储在known_hosts文件中。你能为此建议一些解决方法吗? 我的代码如下:

        Tamir.SharpSsh.jsch.Session mySession = myJsch.getSession(_UserName,_ftpURL, _Port);
        mySession.setPassword(_Password);

         Hashtable config = new Hashtable();
        config.Add("StrictHostKeyChecking", "yes");            

        mySession.setConfig(config);

        byte[] fingerPrint_bytes = new byte[fingerPrint.Length * sizeof(char)];
        System.Buffer.BlockCopy(fingerPrint.ToCharArray(), 0, fingerPrint_bytes, 0, fingerPrint_bytes.Length);

        UserInfo ui=new MyUserInfo();
        mySession.setUserInfo(ui);

        myJsch.getHostKeyRepository().add(_ftpURL, fingerPrint_bytes, ui);
        mySession.connect(); 

0 个答案:

没有答案
相关问题