Rogan Dawes said:
Google for "Java ssh2 scp"?
Go on, just try it! Hint: The 5th link pointing to linuxmafia is the one
you want. . . . .
Can anyone out there comment on some of the ssh packages for java?
Have you tried any of them and were you happy with them? I tried
using jsch, it is one of the optional packages that ant 1.6+ uses for
its ssh tasks. I was trying to figure out how to execute commands via
ssh. The jsch packages seems like its built more for tunnelling X or
something..... It launches threads for input, error and output
streams and you have to wait for them to complete and there is no
event notification (like a listener) to tell you when IO is done.
I looked at the ant 1.6.2 code and it used a loop with a half-second
sleep.
[Snippet from ant.taskdefs.optional.ssh.SSHExec.java]
// execute the command
Session session = openSession();
session.setTimeout((int) maxwait);
final ChannelExec channel = (ChannelExec)
session.openChannel("exec");
channel.setCommand(command);
channel.setOutputStream(tee);
channel.setExtOutputStream(tee);
channel.connect();
// wait for it to finish
thread =
new Thread() {
public void run() {
while (!channel.isEOF()) {
if (thread == null) {
return;
}
try {
sleep(500);
} catch (Exception e) {
// ignored
}
}
}
};
thread.start();
thread.join(maxwait);
[end code snippet]
I thought it was a little messy and clumsy to have to code a sleep in
there to wait for IO completion of the ssh exec task.
I also looked at SSHTools and the API seemed very complicated.
Perhaps I'll take a look at it again, but I really didn't want to
write code to check keystores myself.