| Interface | Description |
|---|---|
| Logger |
Really simple logging interface.
|
| SshBannerHandler |
Call back that is invoked when to display a banner message (during
authentication)
|
| SshChannel |
Interface for custom channels created by
SshChannelHandler
implementations. |
| SshChannel.ChannelData |
Encapsulate details needed for channel creation
|
| SshChannelHandler |
SSH allows custom channels to be handled.
|
| SshChannelListener | |
| SshClient |
Client implementations are responsible for maintaining the connection with
the server, authentication, and access to the sub-systems
|
| SshDataListener |
Interface to be implemented by listeners who wish to receive events about
SshLifecycleComponent opening, closing and data transfer. |
| SshDataProducingComponent |
Interface to be implemented by any lifecycle components that might produce
data that can be listened to.
|
| SshExtendedStreamChannel |
Extension of a
SshStreamChannel that adds the Extended Input Stream,
used for STDERR. |
| SshFileTransferClient |
Interface to be implemented by components that can produce file transfer
events, such as SFTP and SCP.
|
| SshFileTransferListener |
Listener that may be implemented to received events about file transfer
progress, for both SCP and SFTP.
|
| SshLifecycleComponent |
Many components of SSHAPI implement this interface, as they all follow the open() / close() pattern.
|
| SshLifecycleListener |
Interface to be implemented by listeners who wish to receive events about
SshLifecycleComponent opening, closing and data transfer. |
| SshPasswordPrompt |
Call-back interface used when passwords or passphrases are needed.
|
| SshPrivateKey |
Represents a private key.
|
| SshProvider |
Every SSH API implementation must provide one implementation of this
interface.
|
| SshProviderFactory |
Implementations are responsible for creating
SshProvider instances. |
| SshPublicKey |
Represents the the public key portion of a key pair.
|
| SshSCPClient |
The SCP client.
|
| SshShell |
A remote shell.
|
| SshStreamChannel |
Extension to
SshLifecycleComponent for channels who expost I/O
streams, such as executing a command, or a SshShell. |
| Class | Description |
|---|---|
| AbstractClient |
Abstract implementation of a
SshClient. |
| AbstractDataProducingComponent |
Abstract implementation of
SshDataProducingComponent that provides
some default common methods. |
| AbstractFileTransferClient |
Abstract implementation of a file transfer client, providing some useful default
methods (currently transfer events).
|
| AbstractLifecycleComponent |
Abstract implementation of an
SshLifecycleComponent, providing some
command methods. |
| AbstractLifecycleComponentWithEvents |
Abstract implementation of an
AbstractLifecycleComponent that fires
events when the lifecycle methods are called. |
| AbstractProvider |
Abstract implementation of an
SshProvider, providing some common
methods. |
| AbstractSCPClient |
Abstract implementation of an SCP client.
|
| AbstractSocket |
Abstract implementation of a
Socket, used by the Tunneled Sockets
feature of SSHAPI and it's providers. |
| Capability |
Represents a feature that a provider implementation is capable of.
|
| DefaultChannelData | |
| DefaultProviderFactory |
Default implementation of a
SshProviderFactory that by default
searches for known implementations on the classpath. |
| Logger.Level |
Log level
|
| SshConfiguration |
Represents configuration of an
SshClient and some attributes /
callbacks that are common to all providers. |
| SshException.Code |
Error code.
|
| SshProxyServerDetails |
Holds details of the proxy server to connect to the remote SSH through.
|
| SshProxyServerDetails.Type |
Proxy sever type.
|
| Exception | Description |
|---|---|
| SshException |
Exception thrown during various SSH operations.
|
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!
..
..
..
}
}
Copyright © 2018. All rights reserved.