我尝试使用 Apache MINA 库查找 SFTP 客户端的 Java 代码,但找不到。
有人可以告诉我如何使用 Apache MINA 库编写一个基于密码身份验证的简单 SFTP 客户端。
https://mina.apache.org/sshd-project/apidocs/org/apache/sshd/client/subsystem/sftp/SftpClient.html https://mina.apache.org/sshd-project/apidocs/org/apache/sshd/client/subsystem/sftp/SftpClient.html
基于中的示例README.md
在根apache-sshd-2.2.0-src
包裹:
SshClient client = SshClient.setupDefaultClient();
// override any default configuration...
client.setSomeConfiguration(...);
client.setOtherConfiguration(...);
client.start();
try (ClientSession session = client.connect(user, host, port).verify(timeout).getSession()) {
session.addPasswordIdentity(password);
session.auth.verify(timeout);
// User-specific factory
try (SftpClient sftp = DefaultSftpClientFactory.INSTANCE.createSftpClient(session)) {
// use sftp here
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)