Constructor and Description |
---|
Ssh2Client()
Default constructor called by SshConnector.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(String key,
Object value)
Add an attribute to this connection object.
|
void |
addChannelFactory(ChannelFactory factory)
Installs a custom channel factory so that the client may respond to
channel open requests.
|
void |
addListener(SshClientListener listener)
Add a listener to this client.
|
void |
addRequestHandler(GlobalRequestHandler handler)
Installs a global request handler so that the client may respond to
global requests.
|
int |
authenticate(SshAuthentication auth)
Authenticate the user.
|
boolean |
cancelRemoteForwarding(String bindAddress,
int bindPort)
Cancel a forwarding request.
|
void |
connect(SshTransport io,
SshContext context,
SshClientConnector connector,
String username,
String localIdentification,
String remoteIdentification,
boolean buffered)
Connect to an SSH server.
|
protected TransportProtocol |
createTransportProtocol(boolean buffered) |
void |
disconnect()
Disconnect from the remote computer.
|
SshClient |
duplicate()
Create an identical version of an SshClient using cached authentication
information and the SshTransport duplicate method.
|
void |
exit() |
void |
forceKeyExchange()
The SSH transport protocol exchanges keys at the beginning of the
session; the specification recommends that these keys be re-exchanged
after each gigabyte of transmitted data or after each hour of connection
time, whichever comes sooner.
|
Object |
getAttribute(String key)
Get a previously added attribute from this object.
|
<T> T |
getAttribute(String key,
T defaultValue)
Get an attribute or default
|
String[] |
getAuthenticationMethods(String username)
Get a list of authentication methods for the user.
|
Thread |
getBackgroundThread() |
int |
getChannelCount()
Get the number of active channels.
|
String |
getCipherInUseCS()
Get the cipher algorithm used to encrypt data sent to the server.
|
String |
getCipherInUseSC()
Get the cipher algorithm used to decrypt data received from the server.
|
String |
getCompressionInUseCS()
Get the compression algorithm used to compress the clients outgoing data.
|
String |
getCompressionInUseSC()
Get the compression algorithm used to decompress the servers data.
|
SshContext |
getContext()
Get the context that created this client.
|
String |
getHost()
Public accessor method for getTransport().getHost().
|
SshPublicKey |
getHostKey() |
String |
getHostKeyInUse()
Returns the host key algorithm used in the last key exchange.
|
String |
getIdent()
The SSH identifier for this host.
|
SshKeyExchangeClient |
getKeyExchangeInstanceInUse() |
String |
getKeyExchangeInUse()
Returns the key exchange algorithm last used.
|
String |
getMacInUseCS()
Get the MAC algorithm used to verify data sent by the client.
|
String |
getMacInUseSC()
Get the MAC algorithm used to verify data sent by the server.
|
String[] |
getRemoteCiphersCS() |
String[] |
getRemoteCiphersSC() |
String[] |
getRemoteCompressionsCS() |
String[] |
getRemoteCompressionsSC() |
String |
getRemoteIdentification()
Returns the identification string supplied by the server during protocol
negotiation.
|
String[] |
getRemoteKeyExchanges() |
String[] |
getRemoteMacsCS() |
String[] |
getRemoteMacsSC() |
String[] |
getRemotePublicKeys() |
SshTransport |
getTransport()
Get the transport this client is running over
|
String |
getUsername()
Return the username used for this connection
|
String |
getUuid() |
int |
getVersion()
Returns the version for this client.
|
boolean |
hasAttribute(String key)
Determine if connection already has an attribute for given key.
|
boolean |
hasBackgroundThread() |
boolean |
isAuthenticated()
Evaluate whether the user has been authenticated.
|
boolean |
isAuthenticationSupported(String method)
Iterate over support mechanisms and return true only if the method
supplied is reported as supported by the remote device.
|
boolean |
isBuffered()
Identifies whether this client is in buffered mode
|
boolean |
isConnected()
Evaluate whether the connection is still alive.
|
void |
openChannel(Ssh2Channel channel,
byte[] requestdata)
Additional method to open a custom SSH2 channel.
|
void |
openChannel(SshAbstractChannel channel)
Additional method to open a custom SSH2 channel.
|
SshTunnel |
openForwardingChannel(String hostname,
int port,
String listeningAddress,
int listeningPort,
String originatingHost,
int originatingPort,
SshTransport sock,
ChannelEventListener listener)
Open a TCPIP forwarding channel to the remote computer.
|
SshClient |
openRemoteClient(String hostname,
int port,
String username)
Open up an SSH client from the remote machine to another remote server.
|
SshClient |
openRemoteClient(String hostname,
int port,
String username,
SshClientConnector con)
Open up an SSH client from the remote machine to another remote server.
|
SshSession |
openSessionChannel()
Open a session on the remote computer.
|
SshSession |
openSessionChannel(ChannelEventListener listener)
Open a session on the remote computer.
|
SshSession |
openSessionChannel(ChannelEventListener listener,
long timeout)
Open a session on the remote computer.
|
Ssh2Session |
openSessionChannel(int windowspace,
int packetsize,
ChannelEventListener listener)
Additional method to open a session with SSH2 specific features.
|
Ssh2Session |
openSessionChannel(int windowspace,
int packetsize,
ChannelEventListener listener,
long timeout) |
SshSession |
openSessionChannel(long timeout)
Open a session on the remote computer.
|
void |
processMessages(long timeout) |
int |
requestRemoteForwarding(String bindAddress,
int bindPort,
String hostToConnect,
int portToConnect,
ForwardingRequestListener listener)
Requests that the remote computer accepts socket connections and forward
them to the local computer.
|
boolean |
sendGlobalRequest(GlobalRequest request,
boolean wantreply)
Sends a global request to the remote side.
|
boolean |
sendGlobalRequest(GlobalRequest request,
boolean wantreply,
long timeout)
Sends a global request to the remote side.
|
void |
setIdleConnectionTimeoutSecs(long seconds) |
String |
toString() |
public Ssh2Client()
public void connect(SshTransport io, SshContext context, SshClientConnector connector, String username, String localIdentification, String remoteIdentification, boolean buffered) throws SshException
SshClient
connect
in interface SshClient
io
- the transport layercontext
- an SSH contextusername
- the users namelocalIdentification
- the local identification stringremoteIdentification
- the remotes identification stringbuffered
- should the connection be buffered (threaded)SshException
protected TransportProtocol createTransportProtocol(boolean buffered)
public String[] getAuthenticationMethods(String username) throws SshException
username
- the name of the userSshException
public void addListener(SshClientListener listener)
SshClient
addListener
in interface SshClient
public boolean isAuthenticationSupported(String method) throws SshException
method
- SshException
public int authenticate(SshAuthentication auth) throws SshException
SshClient
Authenticate the user. Once connected call to authenticate the user. When a connection is made no other operations can be performed until the user has been authenticated.
authenticate
in interface SshClient
auth
- the authentication mechanism.SshException
public boolean isAuthenticated()
SshClient
true
immediatley
after connection. No other operations can be perform until the user has been
authenticated.isAuthenticated
in interface SshClient
true
if the connection is authenticated, otherwise false
public void disconnect()
SshClient
disconnect
in interface SshClient
public boolean isConnected()
SshClient
isConnected
in interface SshClient
true
if connected, otherwise false
public void forceKeyExchange() throws SshException
SshException
public SshSession openSessionChannel() throws SshException, ChannelOpenException
SshClient
Open a session on the remote computer. This can only be called once the user has been authenticated. The session returned is uninitialized and will be opened when either a command is executed or the users shell has been started.
openSessionChannel
in interface SshClient
SshException
ChannelOpenException
public SshSession openSessionChannel(long timeout) throws SshException, ChannelOpenException
SshClient
Open a session on the remote computer. This can only be called once the user has been authenticated. The session returned is uninitialized and will be opened when either a command is executed or the users shell has been started.
openSessionChannel
in interface SshClient
timeout
- this is an advanced option and should be set to anything other than zero with caution. This is not a socket timeout.SshException
ChannelOpenException
public SshSession openSessionChannel(ChannelEventListener listener, long timeout) throws SshException, ChannelOpenException
SshClient
Open a session on the remote computer. This can only be called once the user has been authenticated. The session returned is uninitialized and will be opened when either a command is executed or the users shell has been started.
openSessionChannel
in interface SshClient
listener
- an event listener to add before openingSshException
ChannelOpenException
public SshSession openSessionChannel(ChannelEventListener listener) throws SshException, ChannelOpenException
SshClient
Open a session on the remote computer. This can only be called once the user has been authenticated. The session returned is uninitialized and will be opened when either a command is executed or the users shell has been started.
openSessionChannel
in interface SshClient
listener
- an event listener to add before openingSshException
ChannelOpenException
public Ssh2Session openSessionChannel(int windowspace, int packetsize, ChannelEventListener listener) throws ChannelOpenException, SshException
openSessionChannel
in interface SshClient
windowspace
- the initial amount of window space availablepacketsize
- the maximum packet sizelistener
- an event listener to add before openingSshException
ChannelOpenException
public Ssh2Session openSessionChannel(int windowspace, int packetsize, ChannelEventListener listener, long timeout) throws ChannelOpenException, SshException
openSessionChannel
in interface SshClient
ChannelOpenException
SshException
public SshClient openRemoteClient(String hostname, int port, String username, SshClientConnector con) throws SshException, ChannelOpenException
SshClient
SshClient
instance to any other machine on the
same network.openRemoteClient
in interface SshClient
hostname
- the name of the remote hostport
- the port of the remote hostusername
- the name of the user on the remote hostcon
- an SshConnector
instance that will be used to connect
the client. This does not have to be the same instance that created
this client.SshException
ChannelOpenException
public SshClient openRemoteClient(String hostname, int port, String username) throws SshException, ChannelOpenException
SshClient
SshClient
instance to any other machine on the
same network.openRemoteClient
in interface SshClient
hostname
- the name of the remote hostport
- the port of the remote hostusername
- the name of the user on the remote hostSshException
ChannelOpenException
public SshTunnel openForwardingChannel(String hostname, int port, String listeningAddress, int listeningPort, String originatingHost, int originatingPort, SshTransport sock, ChannelEventListener listener) throws SshException, ChannelOpenException
SshClient
Open a TCPIP forwarding channel to the remote computer. If successful the remote computer will open a socket to the host/port specified and return a channel which can be used to forward TCPIP data from the local computer to the remotley connected socket.
It should be noted that this is a low level API method and it does not connect the transport to the channel as this would require some threading. The transport is passed here so that it can be attached to the SshTunnel that is returned. If you want to have the API automatically connect the channel to the transport you should use the ForwardingClient which provides management of forwarding connections and threads.
openForwardingChannel
in interface SshClient
hostname
- the host to connect toport
- the port to connect tooriginatingHost
- the originating host (informational only)originatingPort
- the originating port (informational only)listener
- an event listener that will be added to the channel before opening.SshException
ChannelOpenException
public int requestRemoteForwarding(String bindAddress, int bindPort, String hostToConnect, int portToConnect, ForwardingRequestListener listener) throws SshException
SshClient
requestRemoteForwarding
in interface SshClient
bindAddress
- the address that the remote computer should listen onbindPort
- the port that the remote computer should listen onhostToConnect
- the host to connect when a connection is establishedportToConnect
- the port to connect when a connection is establishedlistener
- a callback interfaceSshException
public boolean cancelRemoteForwarding(String bindAddress, int bindPort) throws SshException
SshClient
cancelRemoteForwarding
in interface SshClient
bindAddress
- the address that the remote computer is listening on.bindPort
- the port that the remote computer is listening on.SshException
public void openChannel(Ssh2Channel channel, byte[] requestdata) throws SshException, ChannelOpenException
channel
- the channel to openrequestdata
- the request dataSshException
ChannelOpenException
public void openChannel(SshAbstractChannel channel) throws SshException, ChannelOpenException
channel
- the channel to openSshException
ChannelOpenException
public void addChannelFactory(ChannelFactory factory) throws SshException
factory
- the channel factorySshException
public SshContext getContext()
SshClient
getContext
in interface SshClient
public void addRequestHandler(GlobalRequestHandler handler) throws SshException
handler
- the global request handlerSshException
public boolean sendGlobalRequest(GlobalRequest request, boolean wantreply) throws SshException
request
- the global requestwantreply
- specifies whether the remote side should send a
success/failure messagetrue
if the request succeeded and wantreply=true,
otherwise false
SshException
public boolean sendGlobalRequest(GlobalRequest request, boolean wantreply, long timeout) throws SshException
request
- the global requestwantreply
- specifies whether the remote side should send a
success/failure messagetimeout
- true
if the request succeeded and wantreply=true,
otherwise false
SshException
public String getRemoteIdentification()
SshClient
getRemoteIdentification
in interface SshClient
public String getUsername()
SshClient
getUsername
in interface SshClient
public SshClient duplicate() throws SshException
SshClient
duplicate
in interface SshClient
SshException
public int getChannelCount()
SshClient
getChannelCount
in interface SshClient
public int getVersion()
SshClient
getVersion
in interface SshClient
public boolean isBuffered()
SshClient
isBuffered
in interface SshClient
public void processMessages(long timeout) throws SshException
SshException
public String getKeyExchangeInUse()
public SshKeyExchangeClient getKeyExchangeInstanceInUse()
public String getHostKeyInUse()
public SshPublicKey getHostKey()
public String getCipherInUseCS()
public String getCipherInUseSC()
public String getMacInUseCS()
public String getMacInUseSC()
public String getCompressionInUseCS()
public String getCompressionInUseSC()
public SshTransport getTransport()
SshClient
getTransport
in interface SshClient
public void addAttribute(String key, Object value)
SshClient
addAttribute
in interface SshClient
public Object getAttribute(String key)
SshClient
getAttribute
in interface SshClient
public <T> T getAttribute(String key, T defaultValue)
SshClient
getAttribute
in interface SshClient
public boolean hasAttribute(String key)
SshClient
hasAttribute
in interface SshClient
public String[] getRemoteKeyExchanges()
public String[] getRemotePublicKeys()
public String[] getRemoteCiphersCS()
public String[] getRemoteCiphersSC()
public String[] getRemoteMacsCS()
public String[] getRemoteMacsSC()
public String[] getRemoteCompressionsCS()
public String[] getRemoteCompressionsSC()
public boolean hasBackgroundThread()
public Thread getBackgroundThread()
public String getIdent()
SshClient
public String getHost()
SshClient
public void setIdleConnectionTimeoutSecs(long seconds)
setIdleConnectionTimeoutSecs
in interface SshClient
Copyright © 2024. All rights reserved.