0

A small question.. I have used sharpSSH to connect to SFTP server with "StrictHostKeyChecking" set to "yes". But, everytime I try to connect to a new SFTP server for the first time it asks me whether I want to trust a particular server finger print or not. Is there a way I can skip this step and accept it programmitically since I want minimal user interaction with this code? Also, I do not want to set "strictHostKeyChecking" to "no". Is there any workaround. I was thinking of adding the fingerprint in the Known_hosts file manually but I think I cannot do so as the finger prints are stored in encrypted format in known_hosts file. Can you please suggest some work-around for this? My code goes as follows:

        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 Answers0