简体   繁体   中英

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.

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

Based on the examples in the README.md in the root 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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM