[英]How to write SFTP client using Apache MINA library
I tried finding Java code for SFTP client using Apache MINA library but couldn't find it.我尝试使用 Apache MINA 库为 SFTP 客户端查找 Java 代码,但找不到。
Could someone show me how to write a simple password authentication based SFTP client using Apache MINA library.有人可以告诉我如何使用 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
Based on the examples in the README.md
in the root of apache-sshd-2.2.0-src
package:基于
apache-sshd-2.2.0-src
包根目录README.md
中的示例:
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.