SSHAPI serves as a simple facade or abstract for various SSH client implementations (or providers as they are known in this API) such as Maverick SSH or JSch.
It allows the user to plug in the required provider at deployment time depending on their needs, for example because of specific performance or licensing requirements.
SSHAPI will search the CLASSPATH for providers, and choose the best one for the requested configuration (or just a default). The behavior of the discovery can be configured using system properties
Specific providers can also be chosen manually at connection time. This makes it possible to use different providers depending on configuration of the connection, yet still use a single API for your application.
The SSHAPI project maintains a number of providers as sub-projects. These providers will track the SSHAPI core and be released at the same time.
| Name | Class | License | Vendor |
| Maverick SSH | net.sf.sshapi.impl.maverick.MaverickSshProvider | BSD / Commercial* | http://www.javassh.com/content/ |
| JSch | net.sf.sshapi.impl.jsch.JschSshProvider | BSD | http://www.jcraft.com/jsch/ |
| J2SSH | net.sf.sshapi.impl.j2ssh.J2SshProvider | GPL | http://sourceforge.net/projects/sshtools/ |
| Ganymed | net.sf.sshapi.impl.ganymed.GanymedProvider | BSD | http://www.ganymed.ethz.ch/ssh2/ |
* The provider implementation is licensed as BSD, but you will require a commercial license for Maverick SSH itself
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.sf.sshapi.DefaultClientFactory;
import net.sf.sshapi.SshClient;
import net.sf.sshapi.SshSession;
import net.sf.sshapi.SshShell;
import net.sf.sshapi.util.SimpleSshAuthenticator;
/**
* This example demonstrates the simplest use of the API, opening up a
* connection, creating a shell, and joining the channel streams to standard
* input / output to create a simple remote shell application.
*/
public class Shell {
public static void main(String[] arg) throws Exception {
// Set the basic configuration for this connection
// Put your own detains in here
String username = "CHANGE_THIS";
String hostname = "CHANGE_THIS";
char[] password = "CHANGE_THIS".toCharArray();
int port = 22;
// Create a new session and authenticate it
SshConfiguration configuration = new SshConfiguration();
SshClient client = configuration.createClient();
SshSession session = client.connect(username, hostname, port);
session.authenticate(new SimplePasswordAuthenticator(password));
// Create a shell on the server and join it to the console
SshShell shell = session.openShell("ansi", 80, 24, 0, 0));
// You can now get the input and output streams from the shell
// object and do what you want with them!
..
..
..
}
}