public class LibsshClient extends AbstractClient
| Modifier and Type | Field and Description |
|---|---|
static int |
FORWARDING_BUFFER_SIZE |
static int |
O_RDONLY |
static int |
O_RDWR |
static int |
O_WRONLY |
static int |
S_IRUSR |
static int |
S_IRWXU |
static int |
S_IWUSR |
static int |
S_IXUSR |
static int |
SCP_BUFFER_SIZE |
static int |
SFTP_BUFFER_SIZE |
| Constructor and Description |
|---|
LibsshClient(SshConfiguration configuration) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
authenticate(SshAuthenticator[] authenticators)
Authenticate.
|
void |
connect(java.lang.String username,
java.lang.String hostname,
int port)
Connect to specified host and port using the provided username.
|
SshExtendedStreamChannel |
createCommand(java.lang.String command)
Execute a command on the remote server.
|
SshPortForward |
createLocalForward(java.lang.String localAddress,
int localPort,
java.lang.String remoteHost,
int remotePort)
Create a local forward.
|
SshPortForward |
createRemoteForward(java.lang.String remoteHost,
int remotePort,
java.lang.String localAddress,
int localPort)
Create a remote forward.
|
SshSCPClient |
createSCPClient()
Create a new SCP client.
|
SftpClient |
createSftpClient()
Create a new SFTP client that may be used to perform file operations.
|
SshShell |
createShell(java.lang.String termType,
int cols,
int rows,
int pixWidth,
int pixHeight,
byte[] terminalModes)
Create a new shell.
|
javax.net.SocketFactory |
createTunneledSocketFactory()
Create a
SocketFactory whose connections are actually tunneled
over this SSH connection and made from the remote machine. |
void |
disconnect()
Disconnect this client.
|
int |
getChannelCount()
Get the number of channels that are currently open.
|
java.lang.String |
getRemoteIdentification()
Get the remote server identification string.
|
int |
getRemoteProtocolVersion()
Get the protocol version.
|
java.lang.String |
getUsername()
Get the currently authenticated user.
|
boolean |
isAuthenticated()
Get if the client is currently authenticated.
|
boolean |
isConnected()
Get if the client is currently connected.
|
protected static com.sun.jna.Pointer |
stringPointer(java.lang.String str) |
addChannelHandler, addPortForwardListener, authenticate, createAuthenticatorMap, createPublicKeySubsystem, firePortForwardChannelClosed, firePortForwardChannelOpened, getConfiguration, getProvider, getTimeout, init, removeChannelHandler, removePortForwardListener, setTimeoutpublic static final int S_IRWXU
public static final int S_IRUSR
public static final int S_IWUSR
public static final int S_IXUSR
public static final int O_RDONLY
public static final int O_WRONLY
public static final int O_RDWR
public static final int SCP_BUFFER_SIZE
public static final int SFTP_BUFFER_SIZE
public static final int FORWARDING_BUFFER_SIZE
public LibsshClient(SshConfiguration configuration)
public void connect(java.lang.String username,
java.lang.String hostname,
int port)
throws SshException
SshClientusername - user namehostname - host nameport - portSshException - on any errorprotected static final com.sun.jna.Pointer stringPointer(java.lang.String str)
public javax.net.SocketFactory createTunneledSocketFactory()
throws SshException
SshClientSocketFactory whose connections are actually tunneled
over this SSH connection and made from the remote machine. This actually
makes use of local port forward, but instead of setting up a local server
socket, the tunnels are accessable as Socket objects.SshExceptionpublic SshSCPClient createSCPClient() throws SshException
SshClientSshClient.createSftpClient().SshException - on any errorpublic boolean authenticate(SshAuthenticator[] authenticators) throws SshException
SshClienttrue is return or an exception is thrown.authenticators - authenticators.true when full authenticated, or false
if more authentication is requiredSshExceptionpublic java.lang.String getRemoteIdentification()
SshClientpublic int getRemoteProtocolVersion()
SshClientSshConfiguration.SSH1_ONLY or SshConfiguration.SSH2_ONLY.public SshPortForward createLocalForward(java.lang.String localAddress, int localPort, java.lang.String remoteHost, int remotePort) throws SshException
SshClient
Once you have created the SshPortForward object, you must start
tunnel using SshPortForward.open(). When you have finished with
the tunnel, call SshPortForward.close() (closed tunnels may be
re-opened by calling the SshPortForward.open() method again).
localAddress - local address to bind to. Use null
to bind to all addresses. Note, this may not be supported by
all implementations.localPort - local port to listen onremoteHost - remote host to tunnel toremotePort - remote port to tunnel toSshException - on any errorpublic SshPortForward createRemoteForward(java.lang.String remoteHost, int remotePort, java.lang.String localAddress, int localPort) throws SshException
SshClient
Once you have created the SshPortForward object, you must start
tunnel using SshPortForward.open(). When you have finished with
the tunnel, call SshPortForward.close() (closed tunnels may be
re-opened by calling the SshPortForward.open() method again).
remoteHost - the address on the remote server to listen. This
must either be null to bind to all address on
that server, or a single address that exists on that server
(including 127.0.0.1).remotePort - remote port to tunnel tolocalAddress - local address to bind to. Use null to
bind to all addresses. Note, this may not be supported by all
implementations.localPort - local port to listen onSshException - on any errorpublic SshShell createShell(java.lang.String termType, int cols, int rows, int pixWidth, int pixHeight, byte[] terminalModes) throws SshException
SshClient
Note, this method does not actually start the shell, you must call
SshLifecycleComponent.open() to do that.
Remember to close the shell when you are finished with it using
SshLifecycleComponent.close().
termType - terminal type, or use null to NOT request a
pseudo terminalcols - width of terminal in characters (use zero if not pseudo
terminal should be requested)rows - height of terminal in characters (use zero if not pseudo
terminal should be requested)pixWidth - width of terminal in pixels (if known, otherwise use
zero)pixHeight - height of terminal in pixels (if known, otherwise use
zero)terminalModes - terminal modes (or null or empty array)SshExceptionpublic SshExtendedStreamChannel createCommand(java.lang.String command) throws SshException
SshClient
Note, this method does not actually start the command, you must call
SshLifecycleComponent.open() to do that.
Remember to close the channel when you are finished with it using
SshLifecycleComponent.close().
command - command to executeSshException - on any errorpublic void disconnect()
throws SshException
SshClientSshExceptionpublic boolean isConnected()
SshClientSshClient.isAuthenticated()public boolean isAuthenticated()
SshClientSshClient.isConnected()public SftpClient createSftpClient() throws SshException
SshClient
Note, this method does not actually start the client, you must call
SshLifecycleComponent.open() to do that.
Remember to close the client when you are finished with it using
SshLifecycleComponent.close().
SshExceptionpublic java.lang.String getUsername()
SshClientpublic int getChannelCount()
SshClientCopyright © 2018. All rights reserved.