How to write SFTP client using Apache MINA library

让人想犯罪 __ 提交于 2020-01-24 01:43:09

问题


I tried finding Java code for SFTP client using Apache MINA library but couldn't find it.

Could someone show me how to write a simple password authentication based SFTP client using Apache MINA library.

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


回答1:


Based on the examples in the readme of apache-sshd-2.2.0-src package:

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


来源:https://stackoverflow.com/questions/55137545/how-to-write-sftp-client-using-apache-mina-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!