Hi,

   +-From: Manikandan Chandrasekaran <[email protected]> --
   |_Date: Wed, 22 Sep 2010 19:10:08 +0530 ____________________________
   |
   |If my known hosts file already has the host key of the remote machine, my
   |connection code works fine. If not, then it doesn't work.

   |My code does the following (high level)
   |* setKnownHosts (to my known hosts file)
   |* Session session = jsch.getSession(user, host, 22);
   |* session.setPassword(password);
   |* session.connect()

   |In case of an exception (UnknownHostKey), I do this:
   |  HostKey hk = session.getHostKey();
   |  HostKeyRepository repo = jsch.getHostKeyRepository();
   |  repo.add(hk, null);

   |Throws a NullPointerException as hk is null. (This makes sense as the
   |session might not have the required info.)  How can I get the host key of
   |the remote machine and add it?

Unfortunately, in the current implementation, 
session.getHostKey() will return null, if you reject to accept 
the remote hostkey.

How about using JSch#setHostKeyRepository() ?

  jsch.setHostKeyRepository(your_HostKeyRepository_impl);
  ...
  session.setConfig("StrictHostKeyChecking", "no");
  session.connect();


Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
    +1-415-578-3454
Skype callto://jcraft/
Twitter: @ymnk

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to