ssh 库 java_Java ssh库:Apache sshd库和JSch库(Java Secure Channel)

1.Apache sshd

Apache sshd是一个SSH协议的100%纯Java库,支持客户端和服务器。sshd库基于Apache MINA项目(可伸缩高性能的异步IO库)。官方网站:http://mina.apache.org/sshd-project/documentation.html

客户端示例代码:

public void clentTest() throwsIOException

{

String cmd="ifconfig";

SshClient client=SshClient.setUpDefaultClient();

client.start();

ClientSession session=client.connect("bellring", "10.2.48.179", 22).await().getSession();

session.addPasswordIdentity("bellring");if(!session.auth().await().isSuccess())

System.out.println("auth failed");

ChannelExec ec=session.createExecChannel(cmd);

ec.setOut(System.out);

ec.open();

ec.waitFor(ClientChannel.CLOSED,0);

ec.close();

client.stop();

}

public void sshdClientSftpTest() throwsIOException, InterruptedException

你可能感兴趣的:(ssh,库,java)