Claus Jørgensen Claus Jørgensen - 2 months ago 38
Java Question

Java SFTP Transfer Library

I'm looking for a dead simple Java Library to use for SFTP file transfers. I don't need any other features beyond that.

I've tried Zehon's, but it's incredible naggy, and I think 8 jar files is a bit crazy for so little functionality as I require.

And the library have to be free (as in free beer), and preferable Open Source (not a requirement).



Edit : I'm going to keep my previous answer, as JSch is still used in many places, but if you need a better-documented library, you can use sshj. An example in how to use it to do sftp can be found here.

Using JSch (a java ssh lib, used by Ant for example), you could do something like that :

    Session session = null;
    Channel channel = null;
    try {
        JSch ssh = new JSch();
        session = ssh.getSession("username", "host", 22);
        channel = session.openChannel("sftp");
        ChannelSftp sftp = (ChannelSftp) channel;
        sftp.put("/path/of/local/file", "/path/of/ftp/file");
    } catch (JSchException e) {
    } catch (SftpException e) {
    } finally {
        if (channel != null) {
        if (session != null) {

Here is another link using JSch to do SFTP.

You can use JSch directly this way, or through Commons VFS, but then you'll have to have both commons vfs jar and jsch jar.