【问题标题】:How to write SFTP client using Apache MINA library如何使用 Apache MINA 库编写 SFTP 客户端
【发布时间】:2019-08-03 20:58:07
【问题描述】:

我尝试使用 Apache MINA 库为 SFTP 客户端查找 Java 代码,但找不到。

谁能告诉我如何使用 Apache MINA 库编写一个简单的基于密码验证的 SFTP 客户端。

https://mina.apache.org/sshd-project/apidocs/org/apache/sshd/client/subsystem/sftp/SftpClient.html

【问题讨论】:

标签: java sftp apache-mina


【解决方案1】:

基于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
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多