Am Fri, 18 Dec 2015 16:46:45 +0100 schrieb Mohamed Boussaa <mohamedbouss...@gmail.com>:
> I did that but I got "connection refused" > > > > StringBuilder outputBuffer = new StringBuilder(); > > > String host="10.0.0.1"; // First level target > > String user="user1"; > > String password="pass1"; > > String tunnelRemoteHost="10.0.0.22"; // The host of the > second target > > String secondPassword="pass2"; > > int port=22; > > > > JSch jsch=new JSch(); > > Session session=jsch.getSession(user, host, port); > > session.setPassword(password); > > localUserInfo lui=new localUserInfo(); > > session.setUserInfo(lui); > > session.setConfig("StrictHostKeyChecking", "no"); > > // create port from 2233 on local system to port 22 on > tunnelRemoteHost > > session.setPortForwardingL(2251, tunnelRemoteHost, 22); > > session.connect(); > > session.openChannel("direct-tcpip"); > > > // create a session connected to port 2233 on the local host. > > Session secondSession = jsch.getSession("user2", > tunnelRemoteHost, 2251); I didn't test or compile anything, but I think this line is wrong. You opened up your tunnel port on the FIRST host. So you have to connect to your first host (ip 10.0.0.1 - called "host" in your code) to reach the second one by tunnel. regards Hajo > > secondSession.setPassword(secondPassword); > > secondSession.setUserInfo(lui); > > secondSession.setConfig("StrictHostKeyChecking", "no"); > > > secondSession.connect(); // now we're connected to the > secondary system > > Channel channel=secondSession.openChannel("exec"); > > ((ChannelExec)channel).setCommand("hostname"); > > > channel.setInputStream(null); > > > InputStream stdout=channel.getInputStream(); > > > channel.connect(); > > ------------------------------------------------------------------------------ > _______________________________________________ > JSch-users mailing list > JSch-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jsch-users ------------------------------------------------------------------------------ _______________________________________________ JSch-users mailing list JSch-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users