My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

Basically, there's only one pure java library that's typically used for ssh tasks, jsch. However, the api for scp transfers in jsch requires a bit of work messing with the input and output streams and working with the ssh protocol. Clients just want to make a couple of method calls. So I wrote this facade for easy scp'ing and am extending it to support other ssh utilities.

As a basis of comparison, here's the example file jsch provides: http://www.jcraft.com/jsch/examples/ScpTo.java

This code basically wraps that behavior behind a simple interface. Compare the code you'd have to write in the link above to the snippet below.

    String host = "foo.bar.com";
    String username = "joe";
    String password = "password"; 
    String remotePath = "foo.txt";
    
    SshConnection ssh = null;
    
    try
    {
      ssh = new SshConnection(host,username,password);
      ssh.connect();
      ScpFile scpFile = new ScpFile(new File("/tmp/foo.txt"),remotePath));      
      ssh.executeTask(new ScpUpload(scpFile));
    }
    catch (SshException e)
    {
      e.printStackTrace();
    }
    finally
    {
      if (ssh != null)
      {
        ssh.disconnect();
      }
    }

Dependencies:

jsch - 0.1.38
Powered by Google Project Hosting