开发者

SSH library for java which very well supports mutithreading!

I'm searching for a library that would allow me to create lets say 3 threads for remote command execution each command to execute takes ~13 min. What s开发者_高级运维sh lib for java would you suggest, which would be able to perform such a task? (free Maveric version - failed not willing to pay 2.4k$ for full library, now fighting using ssh2...)


I know from personal experience that JSch works fine for this as long as you create a separate SSH connection for each thread. There's also sshj and Ganymed SSH-2 that you might want to check out.

Here's a quick example of remote command execution with JSch:

JSch jsch = new JSch();

Session session = jsch.getSession(user, host);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect(timeout);

Channel channel = session.openChannel("exec");
ChannelExec channelExec = (ChannelExec) channel;
channelExec.setCommand(command);
channel.connect();

// read channel.getInputStream() here if you want to capture the output

channel.disconnect();
session.disconnect();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜