See my answer here, it includes a link to the official JSCH example for creating an interative ssh session with jsch. I also posted an improvement to their program, which allows it to properly close the session when you exit.
shell prompt to fire multiple commands using jsch
Question
I can successfully connect to my remote ssh server using the jsch library and fire a single command and see its result. I am using "exec" to send the 'ls' command and able to see the list of files. Is there a way to open a shell prompt so that i can fire multiple command to the server.
JSch jsch=new JSch();
Properties props = new Properties();
props.put("StrictHostKeyChecking", "no");
Session session;
try {
session = jsch.getSession(user, host,22);
session.setConfig(props);
session.setPassword(password);
session.connect(20000);
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("ls");
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect(20000);
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow