0

一个小问题..我使用sharpSSH连接到SFTP服务器,“StrictHostKeyChecking”设置为“yes”。但是,每次我第一次尝试连接到新的 SFTP 服务器时,它都会询问我是否要信任特定的服务器指纹。有没有一种方法可以跳过此步骤并以编程方式接受它,因为我希望用户与此代码的交互最少?此外,我不想将“strictHostKeyChecking”设置为“否”。是否有任何解决方法。我正在考虑手动在 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(); 
4

0 回答 0