public interface ClientSession extends Session, ClientAuthenticationManager
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 ClientAuthenticationManager.addPasswordIdentity(String)
or
ClientAuthenticationManager.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(Collection, long)
method can be used to listen to specific
events such as the session being established, authenticated or closed.
Closeable.close(boolean)
method.Modifier and Type | Interface and Description |
---|---|
static class |
ClientSession.ClientSessionEvent |
Session.AttributeKey<T>, Session.TimeoutStatus
SignatureFactoriesManager.Utils
DEFAULT_SSH_VERSION_PREFIX
DEFAULT_PASSWORD_PROMPTS, PASSWORD_PROMPTS, PREFERRED_AUTHS
Modifier and Type | Method and Description |
---|---|
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(int version)
Creates an SFTP client using the specified version
|
SftpClient |
createSftpClient(SftpVersionSelector selector)
Creates an SFTP client while allowing the selection of a specific version
|
FileSystem |
createSftpFileSystem() |
FileSystem |
createSftpFileSystem(int version) |
FileSystem |
createSftpFileSystem(int readBufferSize,
int writeBufferSize) |
FileSystem |
createSftpFileSystem(int version,
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() |
void |
setScpTransferEventListener(ScpTransferEventListener listener) |
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.
|
KeyExchangeFuture |
switchToNoneCipher()
Switch to a none cipher for performance.
|
Set<ClientSession.ClientSessionEvent> |
waitFor(Collection<ClientSession.ClientSessionEvent> mask,
long timeout)
Wait for any one of a specific state to be signaled.
|
createBuffer, createBuffer, disconnect, exceptionCaught, getAttribute, getAuthTimeout, getCipherInformation, getClientVersion, getCompressionInformation, getIdleTimeout, getIoSession, getKex, getMacInformation, getNegotiatedKexParameter, getServerVersion, getService, getSessionId, getTimeoutStatus, isAuthenticated, prepareBuffer, reExchangeKeys, request, resetIdleTimeout, setAttribute, setAuthenticated, startService, writePacket, writePacket
getCipherFactories, getCompressionFactories, getKeyExchangeFactories, getMacFactories, setCipherFactories, setCompressionFactories, setKeyExchangeFactories, setMacFactories
getKeyPairProvider, setKeyPairProvider
getSignatureFactories, setSignatureFactories
addSessionListener, getSessionListenerProxy, removeSessionListener
addChannelListener, getChannelListenerProxy, removeChannelListener
getParentPropertyResolver, getProperties
setUsername
getUsername
addPasswordIdentity, addPublicKeyIdentity, getPasswordIdentityProvider, getRegisteredIdentities, getServerKeyVerifier, getUserAuthFactories, getUserInteraction, removePasswordIdentity, removePublicKeyIdentity, setPasswordIdentityProvider, setServerKeyVerifier, setUserAuthFactories, setUserInteraction
AuthFuture auth() throws IOException
ClientAuthenticationManager.addPasswordIdentity(String)
or ClientAuthenticationManager.addPublicKeyIdentity(java.security.KeyPair)
.IOException
- if failed to generate the futureClientAuthenticationManager.addPasswordIdentity(String)
,
ClientAuthenticationManager.addPublicKeyIdentity(java.security.KeyPair)
ClientChannel createChannel(String type) throws IOException
createChannel(type, null)
.type
- The channel typeClientChannel
IOException
- If failed to create the requested channelClientChannel createChannel(String type, String subType) throws IOException
type
- The channel typesubType
- The channel sub-typeClientChannel
IOException
- If failed to create the requested channelChannelShell createShellChannel() throws IOException
ChannelShell
IOException
- If failed to create the requested channelChannelExec createExecChannel(String command) throws IOException
command
- The command to executeChannelExec
IOException
- If failed to create the requested channelChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
subsystem
- The subsystem nameChannelSubsystem
IOException
- If failed to create the requested channelChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
local
- The local addressremote
- The remote addressChannelDirectTcpip
IOException
- 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
SftpClient
IOException
- if failed to create the clientSftpClient createSftpClient(int version) throws IOException
version
- The version to use - Note: if the specified
version is not supported by the server then an exception
will occurSftpClient
IOException
- If failed to create the client or use the specified versionSftpClient 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 versionSftpClient
IOException
- If failed to create the client or re-negotiateFileSystem createSftpFileSystem() throws IOException
IOException
FileSystem createSftpFileSystem(int version) throws IOException
IOException
FileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException
IOException
FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException
IOException
FileSystem createSftpFileSystem(int version, int readBufferSize, int writeBufferSize) throws IOException
IOException
FileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException
IOException
SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
local
- The local addressremote
- The remote addressSshdSocketAddress
IOException
- 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 addressSshdSocketAddress
IOException
- 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 addressSshdSocketAddress
IOException
- If failed to create the requested bindingvoid stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
local
- The local addressIOException
- If failed to cancel the requested bindingSet<ClientSession.ClientSessionEvent> waitFor(Collection<ClientSession.ClientSessionEvent> mask, long timeout)
mask
- The request ClientSession.ClientSessionEvent
s masktimeout
- Wait time in milliseconds - non-positive means foreverClientSession.ClientSessionEvent.TIMEOUT
value is set)Map<Object,Object> getMetadataMap()
Map
ClientFactoryManager getFactoryManager()
getFactoryManager
in interface Session
KeyExchangeFuture 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.
KeyExchangeFuture
that can be used to wait for the exchange
to be finishedIOException
- if a key exchange is already runningCopyright © 2008–2016 The Apache Software Foundation. All rights reserved.