public interface ClientSession extends Session
An authenticated session to a given SSH server
A client session is established using the SshClient.
Once the session has been created, the user has to authenticate
using either addPasswordIdentity(String) or
addPublicKeyIdentity(java.security.KeyPair) followed by
a call to {$link #auth()}.
From this session, channels can be created using the
createChannel(String) method. Multiple channels can
be created on a given session concurrently.
When using the client in an interactive mode, the
waitFor(int, long) method can be used to listen to specific
events such as the session being established, authenticated or closed.
Closeable.close(boolean) method.Session.AttributeKey<T>, Session.TimeoutStatus| Modifier and Type | Field and Description |
|---|---|
static int |
AUTHED |
static int |
CLOSED |
static int |
TIMEOUT |
static int |
WAIT_AUTH |
| Modifier and Type | Method and Description |
|---|---|
void |
addPasswordIdentity(String password) |
void |
addPublicKeyIdentity(KeyPair key) |
AuthFuture |
auth()
Starts the authentication process.
|
ClientChannel |
createChannel(String type)
Create a channel of the given type.
|
ClientChannel |
createChannel(String type,
String subType)
Create a channel of the given type and sub-type.
|
ChannelDirectTcpip |
createDirectTcpipChannel(SshdSocketAddress local,
SshdSocketAddress remote)
Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
|
ChannelExec |
createExecChannel(String command)
Create a channel to execute a command.
|
ScpClient |
createScpClient()
Create an SCP client from this session.
|
ScpClient |
createScpClient(ScpTransferEventListener listener)
Create an SCP client from this session.
|
SftpClient |
createSftpClient()
Create an SFTP client from this session.
|
SftpClient |
createSftpClient(SftpVersionSelector selector) |
FileSystem |
createSftpFileSystem() |
FileSystem |
createSftpFileSystem(int readBufferSize,
int writeBufferSize) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector,
int readBufferSize,
int writeBufferSize) |
ChannelShell |
createShellChannel()
Create a channel to start a shell.
|
ChannelSubsystem |
createSubsystemChannel(String subsystem)
Create a subsystem channel.
|
ClientFactoryManager |
getFactoryManager() |
Map<Object,Object> |
getMetadataMap()
Access to the metadata.
|
ScpTransferEventListener |
getScpTransferEventListener() |
UserInteraction |
getUserInteraction() |
String |
removePasswordIdentity(String password) |
KeyPair |
removePublicKeyIdentity(KeyPair kp) |
void |
setScpTransferEventListener(ScpTransferEventListener listener) |
void |
setUserInteraction(UserInteraction userInteraction) |
SshdSocketAddress |
startDynamicPortForwarding(SshdSocketAddress local)
Start dynamic local port forwarding using a SOCKS proxy.
|
SshdSocketAddress |
startLocalPortForwarding(SshdSocketAddress local,
SshdSocketAddress remote)
Start forwarding the given local address on the client to the given address on the server.
|
SshdSocketAddress |
startRemotePortForwarding(SshdSocketAddress remote,
SshdSocketAddress local)
Start forwarding tcpip from the given address on the server to the
given address on the client.
|
void |
stopDynamicPortForwarding(SshdSocketAddress local)
Stop a previously started dynamic port forwarding.
|
void |
stopLocalPortForwarding(SshdSocketAddress local)
Stop forwarding the given local address.
|
void |
stopRemotePortForwarding(SshdSocketAddress remote)
Stop forwarding of the given remote address.
|
SshFuture |
switchToNoneCipher()
Switch to a none cipher for performance.
|
int |
waitFor(int mask,
long timeout)
Wait for a specific state.
|
addListener, createBuffer, createBuffer, disconnect, exceptionCaught, getAttribute, getAuthTimeout, getClientVersion, getIdleTimeout, getIntProperty, getIoSession, getKex, getNegotiatedKexParameter, getServerVersion, getService, getSessionId, getTimeoutStatus, getUsername, isAuthenticated, reExchangeKeys, removeListener, request, resetIdleTimeout, setAttribute, setAuthenticated, setUsername, startService, writePacket, writePacketstatic final int TIMEOUT
static final int CLOSED
static final int WAIT_AUTH
static final int AUTHED
void addPasswordIdentity(String password)
password - Password to be added - may not be null/emptyString removePasswordIdentity(String password)
password - The password to remove - ignored if null/emptyaddPasswordIdentity(String) - or null if no
match foundvoid addPublicKeyIdentity(KeyPair key)
key - The KeyPair to add - may not be nullKeyPair removePublicKeyIdentity(KeyPair kp)
kp - The KeyPair to remove - ignored if nullKeyPair - same one that was added via
addPublicKeyIdentity(KeyPair) - or null if no
match foundUserInteraction getUserInteraction()
void setUserInteraction(UserInteraction userInteraction)
AuthFuture auth() throws IOException
addPasswordIdentity(String) or addPublicKeyIdentity(java.security.KeyPair).IOException - if failed to generate the futureaddPasswordIdentity(String),
addPublicKeyIdentity(java.security.KeyPair)ClientChannel createChannel(String type) throws IOException
createChannel(type, null).type - The channel typeClientChannelIOException - If failed to create the requested channelClientChannel createChannel(String type, String subType) throws IOException
type - The channel typesubType - The channel sub-typeClientChannelIOException - If failed to create the requested channelChannelShell createShellChannel() throws IOException
ChannelShellIOException - If failed to create the requested channelChannelExec createExecChannel(String command) throws IOException
command - The command to executeChannelExecIOException - If failed to create the requested channelChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
subsystem - The subsystem nameChannelSubsystemIOException - If failed to create the requested channelChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
local - The local addressremote - The remote addressChannelDirectTcpipIOException - If failed to create the requested channelScpClient createScpClient()
ScpClient instance. Note: uses the currently
registered ScpTransferEventListener if anysetScpTransferEventListener(ScpTransferEventListener)ScpClient createScpClient(ScpTransferEventListener listener)
listener - A ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are required. Note: this listener
is used instead of any listener set via setScpTransferEventListener(ScpTransferEventListener)ScpClient instanceScpTransferEventListener getScpTransferEventListener()
ScpTransferEventListener set via
setScpTransferEventListener(ScpTransferEventListener)void setScpTransferEventListener(ScpTransferEventListener listener)
listener - A default ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are requiredcreateScpClient(ScpTransferEventListener)SftpClient createSftpClient() throws IOException
SftpClientIOException - if failed to create the clientSftpClient createSftpClient(SftpVersionSelector selector) throws IOException
selector - The SftpVersionSelector to use - Note:
if the server does not support versions re-negotiation then the
selector will be presented with only one "choice" - the
current versionSftpClientIOException - If failed to create the client or re-negotiateFileSystem createSftpFileSystem() throws IOException
IOExceptionFileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException
IOExceptionFileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException
IOExceptionFileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException
IOExceptionSshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
local - The local addressremote - The remote addressSshdSocketAddressIOException - If failed to create the requested bindingvoid stopLocalPortForwarding(SshdSocketAddress local) throws IOException
local - The local addressIOException - If failed to cancel the requested bindingSshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException
Start forwarding tcpip from the given address on the server to the given address on the client.
The remote host name is the address to bind to on the server:local - The local addressremote - The remote addressSshdSocketAddressIOException - If failed to create the requested bindingvoid stopRemotePortForwarding(SshdSocketAddress remote) throws IOException
remote - The remote addressIOException - If failed to cancel the requested bindingSshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException
local - The local addressSshdSocketAddressIOException - If failed to create the requested bindingvoid stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
local - The local addressIOException - If failed to cancel the requested bindingint waitFor(int mask,
long timeout)
mask - The request masktimeout - Wait time in milliseconds - non-positive means foreverTIMEOUT
bit is set)Map<Object,Object> getMetadataMap()
MapClientFactoryManager getFactoryManager()
getFactoryManager in interface SessionSshFuture switchToNoneCipher() throws IOException
Switch to a none cipher for performance.
This should be done after the authentication phase has been performed. After such a switch, interactive channels are not allowed anymore. Both client and server must have been configured to support the none cipher. If that's not the case, the returned future will be set with an exception.
SshFuture that can be used to wait for the exchange
to be finishedIOException - if a key exchange is already runningCopyright © 2008–2015 The Apache Software Foundation. All rights reserved.