Package com.sshtools.client
Class SshClient
java.lang.Object
com.sshtools.client.SshClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static final class
static final class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSshClient
(com.sshtools.common.ssh.SshConnection con) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(com.sshtools.common.ssh.SshConnection con, boolean closeConnection) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, char[] password, SshClientContext context) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, long connectTimeout, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, long connectTimeout, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, long connectTimeout, File key, String passphrase) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, SshClientContext sshContext, long connectTimeout, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, SshClientContext sshContext, long connectTimeout, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, SshClientContext sshContext, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, int port, String username, com.sshtools.common.ssh.components.SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, Integer port, String username, char[] password, File key, String passphrase) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, Integer port, String username, long connectTimeout, char[] password, File key, String passphrase) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, Integer port, String username, SshClientContext sshContext) Deprecated, for removal: This API element is subject to removal in a future version.SshClient
(String hostname, Integer port, String username, SshClientContext sshContext, long connectTimeout) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionboolean
authenticate
(ClientAuthenticator authenticator, long timeout) void
close()
protected void
configure
(SshClientContext sshContext) Deprecated, for removal: This API element is subject to removal in a future version.void
protected final com.sshtools.synergy.ssh.Connection<SshClientContext>
doConnect
(String hostname, int port, SshClientContext sshContext, long connectTimeout, List<String> keys) protected <T extends Task>
TdoTask
(T task, long timeout) executeCommand
(String cmd) executeCommand
(String cmd, long timeout) executeCommand
(String cmd, long timeout, String charset) executeCommand
(String cmd, String charset) int
int
executeCommandWithResult
(String cmd, StringBuffer buffer) int
executeCommandWithResult
(String cmd, StringBuffer buffer, long timeout) int
executeCommandWithResult
(String cmd, StringBuffer buffer, long timeout, String charset) int
executeCommandWithResult
(String cmd, StringBuffer buffer, String charset) com.sshtools.synergy.ssh.Connection<SshClientContext>
void
void
com.sshtools.common.forwarding.ForwardingPolicy
getHost()
com.sshtools.common.ssh.components.SshPublicKey
int
getPort()
String[]
boolean
boolean
static void
openRemoteClient
(String hostname, int port, String username) openSessionChannel
(boolean autoConsume) openSessionChannel
(long timeout) openSessionChannel
(long timeout, boolean autoConsume) void
void
void
<T extends Task>
voidrunTask
(T task) <T extends Task>
voidrunTask
(T task, long timeout) int
startLocalForwarding
(String addressToBind, int portToBind, String destinationHost, int destinationPort) int
startLocalForwarding
(String addressToBind, String destinationHost) int
startRemoteForwarding
(String addressToBind, int portToBind, String destinationHost, int destinationPort) int
startRemoteForwarding
(String addressToBind, String destinationHost) void
void
stopLocalForwarding
(String addressToBind, int portToBind) void
void
stopRemoteForwarding
(String addressToBind, int portToBind)
-
Field Details
-
GUEST_USERNAME
-
DEFAULT_CONNECT_TIMEOUT
public static final long DEFAULT_CONNECT_TIMEOUT
-
-
Constructor Details
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, char[] password) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutpassword
- password- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, char[] password) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userpassword
- password- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, char[] password, SshClientContext context) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userpassword
- passwordsshContext
- context- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, File key) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutkey
- key file- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, File key) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userkey
- key file- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, File key, String passphrase) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutkey
- key filepassphrase
- key passphrase- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, File key, String passphrase) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userkey
- key filepassphrase
- key passphrase- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- useridentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshClientContext sshContext, long connectTimeout, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- contextconnectTimeout
- timeoutidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshClientContext sshContext, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- contextidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutpassword
- passwordidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userpassword
- passwordidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, long connectTimeout, char[] password, File key, String passphrase) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeoutpassword
- passwordkey
- key filepassphrase
- key passphrase- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, char[] password, File key, String passphrase) throws IOException, com.sshtools.common.ssh.SshException, com.sshtools.common.publickey.InvalidPassphraseException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userpassword
- passwordkey
- keypassphrase
- passphrase- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH errorcom.sshtools.common.publickey.InvalidPassphraseException
- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, long connectTimeout) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- userconnectTimeout
- timeout- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- user- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, SshClientContext sshContext, long connectTimeout) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- contextconnectTimeout
- timeout- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, SshClientContext sshContext) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- context- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(com.sshtools.common.ssh.SshConnection con) Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- contextconnectTimeout
- timeoutpassword
- passwordidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(com.sshtools.common.ssh.SshConnection con, boolean closeConnection) Deprecated, for removal: This API element is subject to removal in a future version. -
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshClientContext sshContext, long connectTimeout, char[] password, com.sshtools.common.ssh.components.SshKeyPair... identities) throws IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Create a new client.- Parameters:
hostname
- hostport
- portusername
- usersshContext
- contextconnectTimeout
- timeoutpassword
- passwordidentities
- identities- Throws:
IOException
- on I/O errorcom.sshtools.common.ssh.SshException
- on general SSH error- See Also:
-
-
Method Details
-
doConnect
protected final com.sshtools.synergy.ssh.Connection<SshClientContext> doConnect(String hostname, int port, SshClientContext sshContext, long connectTimeout, List<String> keys) throws com.sshtools.common.ssh.SshException, IOException - Throws:
com.sshtools.common.ssh.SshException
IOException
-
configure
@Deprecated(since="3.1.0", forRemoval=true) protected void configure(SshClientContext sshContext) throws com.sshtools.common.ssh.SshException, IOException Deprecated, for removal: This API element is subject to removal in a future version.Further configuration the client context.- Parameters:
sshContext
-- Throws:
com.sshtools.common.ssh.SshException
IOException
- See Also:
-
}.
-
addTask
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getContext
-
getConnection
-
getForwardingPolicy
public com.sshtools.common.forwarding.ForwardingPolicy getForwardingPolicy() -
startLocalForwarding
public int startLocalForwarding(String addressToBind, String destinationHost) throws com.sshtools.common.permissions.UnauthorizedException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.permissions.UnauthorizedException
com.sshtools.common.ssh.SshException
-
startLocalForwarding
public int startLocalForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) throws com.sshtools.common.permissions.UnauthorizedException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.permissions.UnauthorizedException
com.sshtools.common.ssh.SshException
-
stopLocalForwarding
-
stopLocalForwarding
public void stopLocalForwarding() -
startRemoteForwarding
public int startRemoteForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
startRemoteForwarding
public int startRemoteForwarding(String addressToBind, String destinationHost) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
stopRemoteForwarding
public void stopRemoteForwarding(String addressToBind, int portToBind) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
stopRemoteForwarding
public void stopRemoteForwarding() throws com.sshtools.common.ssh.SshException- Throws:
com.sshtools.common.ssh.SshException
-
isConnected
public boolean isConnected() -
disconnect
public void disconnect() -
doTask
- Throws:
IOException
-
getFile
- Throws:
IOException
-
getFile
- Throws:
IOException
-
getFile
- Throws:
IOException
-
getFile
- Throws:
IOException
-
putFile
- Throws:
IOException
-
putFile
- Throws:
IOException
-
putFile
- Throws:
IOException
-
executeCommand
- Throws:
IOException
-
executeCommand
- Throws:
IOException
-
executeCommand
- Throws:
IOException
-
executeCommand
- Throws:
IOException
-
executeCommandWithResult
- Throws:
IOException
-
executeCommandWithResult
- Throws:
IOException
-
executeCommandWithResult
public int executeCommandWithResult(String cmd, StringBuffer buffer, long timeout) throws IOException - Throws:
IOException
-
executeCommandWithResult
public int executeCommandWithResult(String cmd, StringBuffer buffer, String charset) throws IOException - Throws:
IOException
-
executeCommandWithResult
public int executeCommandWithResult(String cmd, StringBuffer buffer, long timeout, String charset) throws IOException - Throws:
IOException
-
getAuthenticationMethods
-
authenticate
public boolean authenticate(ClientAuthenticator authenticator, long timeout) throws IOException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.ssh.SshException
-
isAuthenticated
public boolean isAuthenticated() -
runTask
- Throws:
IOException
-
runTask
- Throws:
IOException
-
getRemotePublicKeys
-
getRemoteIdentification
-
getLocalIdentification
-
getHost
-
getHostKey
public com.sshtools.common.ssh.components.SshPublicKey getHostKey() -
openSessionChannel
- Throws:
com.sshtools.common.ssh.SshException
-
openSessionChannel
public SessionChannelNG openSessionChannel(long timeout) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
openSessionChannel
public SessionChannelNG openSessionChannel(boolean autoConsume) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
openSessionChannel
public SessionChannelNG openSessionChannel(long timeout, boolean autoConsume) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
openRemoteClient
public SshClient openRemoteClient(String hostname, int port, String username) throws com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.UnauthorizedException - Throws:
com.sshtools.common.ssh.SshException
IOException
com.sshtools.common.permissions.UnauthorizedException
-
getPort
public int getPort() -
main
- Throws:
IOException
com.sshtools.common.ssh.SshException
-