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 interfacestatic final classstatic final class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSshClient(SshConnection con) Deprecated, for removal: This API element is subject to removal in a future version.SshClient(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, 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, 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, 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, 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, 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, SshKeyPair... identities) Deprecated, for removal: This API element is subject to removal in a future version.SshClient(String hostname, int port, String username, 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 TypeMethodDescriptionbooleanauthenticate(ClientAuthenticator authenticator, long timeout) voidclose()protected voidconfigure(SshClientContext sshContext) Deprecated, for removal: This API element is subject to removal in a future version.voidprotected final 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) intintexecuteCommandWithResult(String cmd, StringBuffer buffer) intexecuteCommandWithResult(String cmd, StringBuffer buffer, long timeout) intexecuteCommandWithResult(String cmd, StringBuffer buffer, long timeout, String charset) intexecuteCommandWithResult(String cmd, StringBuffer buffer, String charset) voidvoidgetHost()intgetPort()String[]booleanbooleanstatic voidopenRemoteClient(String hostname, int port, String username) openSessionChannel(boolean autoConsume) openSessionChannel(long timeout) openSessionChannel(long timeout, boolean autoConsume) voidvoidvoid<T extends Task>
voidrunTask(T task) <T extends Task>
voidrunTask(T task, long timeout) intstartLocalForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) intstartLocalForwarding(String addressToBind, String destinationHost) intstartRemoteForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) intstartRemoteForwarding(String addressToBind, String destinationHost) voidvoidstopLocalForwarding(String addressToBind, int portToBind) voidvoidstopRemoteForwarding(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, 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 errorSshException- 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, 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 errorSshException- 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, 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 errorSshException- 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, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, File key) throws IOException, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- 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, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, File key, String passphrase) throws IOException, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, long connectTimeout, SshKeyPair... identities) throws IOException, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshKeyPair... identities) throws IOException, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshClientContext sshContext, long connectTimeout, SshKeyPair... identities) throws IOException, 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 errorSshException- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, SshClientContext sshContext, SshKeyPair... identities) throws IOException, 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 errorSshException- 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, SshKeyPair... identities) throws IOException, 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 errorSshException- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, int port, String username, char[] password, SshKeyPair... identities) throws IOException, 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 errorSshException- 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, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- 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, SshException, 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 errorSshException- on general SSH errorInvalidPassphraseException- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username, long connectTimeout) throws IOException, 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 errorSshException- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(String hostname, Integer port, String username) throws IOException, 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 errorSshException- 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, 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 errorSshException- 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, 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 errorSshException- on general SSH error- See Also:
-
SshClient
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 errorSshException- on general SSH error- See Also:
-
SshClient
@Deprecated(since="3.1.0", forRemoval=true) public SshClient(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, SshKeyPair... identities) throws IOException, 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 errorSshException- on general SSH error- See Also:
-
-
Method Details
-
doConnect
protected final Connection<SshClientContext> doConnect(String hostname, int port, SshClientContext sshContext, long connectTimeout, List<String> keys) throws SshException, IOException - Throws:
SshExceptionIOException
-
configure
@Deprecated(since="3.1.0", forRemoval=true) protected void configure(SshClientContext sshContext) throws SshException, IOException Deprecated, for removal: This API element is subject to removal in a future version.Further configuration the client context.- Parameters:
sshContext-- Throws:
SshExceptionIOException- See Also:
-
}.
-
addTask
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getContext
-
getConnection
-
getForwardingPolicy
-
startLocalForwarding
public int startLocalForwarding(String addressToBind, String destinationHost) throws UnauthorizedException, SshException - Throws:
UnauthorizedExceptionSshException
-
startLocalForwarding
public int startLocalForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) throws UnauthorizedException, SshException - Throws:
UnauthorizedExceptionSshException
-
stopLocalForwarding
-
stopLocalForwarding
public void stopLocalForwarding() -
startRemoteForwarding
public int startRemoteForwarding(String addressToBind, int portToBind, String destinationHost, int destinationPort) throws SshException - Throws:
SshException
-
startRemoteForwarding
- Throws:
SshException
-
stopRemoteForwarding
- Throws:
SshException
-
stopRemoteForwarding
- Throws:
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, SshException - Throws:
IOExceptionSshException
-
isAuthenticated
public boolean isAuthenticated() -
runTask
- Throws:
IOException
-
runTask
- Throws:
IOException
-
getRemotePublicKeys
-
getRemoteIdentification
-
getLocalIdentification
-
getHost
-
getHostKey
-
openSessionChannel
- Throws:
SshException
-
openSessionChannel
- Throws:
SshException
-
openSessionChannel
- Throws:
SshException
-
openSessionChannel
- Throws:
SshException
-
openRemoteClient
public SshClient openRemoteClient(String hostname, int port, String username) throws SshException, IOException, UnauthorizedException -
getPort
public int getPort() -
main
- Throws:
IOExceptionSshException
-