Package com.sshtools.client
Class SshClient.SshClientBuilder
java.lang.Object
com.sshtools.client.SshClient.SshClientBuilder
- Enclosing class:
- SshClient
-
Method Summary
Modifier and TypeMethodDescriptionaddAuthenticators
(ClientAuthenticator... authenticators) Add one or moreClientAuthenticator
instances that will be presented to the server one at a time.addAuthenticators
(Collection<ClientAuthenticator> authenticators) Add one or moreClientAuthenticator
instances that will be presented to the server one at a time.addIdentities
(com.sshtools.common.ssh.components.SshKeyPair... identities) Add on more identities (key pairs) to use for authentication.addIdentities
(Collection<com.sshtools.common.ssh.components.SshKeyPair> identities) Add a key pair to use for authentication.build()
Build a newSshClient.SshClientBuilder
set.static SshClient.SshClientBuilder
create()
Create a newSshClient.SshClientBuilder
create
(com.sshtools.common.ssh.SshConnection connection) Create a newSshClient.SshClientBuilder
using an existing connection.onConfigure
(SshClient.OnConfiguration onConfigure) Set aConsumer
that receives aSshClientContext
when the connection is ready for configuration.withAuthenticators
(ClientAuthenticator... authenticators) Set the list of one or moreClientAuthenticator
instances that will be presented to the server one at a time.withAuthenticators
(Collection<ClientAuthenticator> authenticators) Set the list of one or moreClientAuthenticator
instances that will be presented to the server one at a time.withConnectTimeout
(long connectTimeout) Set the connection timeout in milliseconds.withConnectTimeout
(Duration connectTimeout) Set the connection timeout.withCurrentUsername
(String username) Set the username to use for authentication as currently local in local user, what is returned bySystem.getProperty("user.name");
.withHost
(InetAddress address) Set the host to use.withHostname
(String hostname) Set the hostname to use.withIdentities
(com.sshtools.common.ssh.components.SshKeyPair... identities) Set one more identities (key pairs) to use for authentication.withIdentities
(Collection<com.sshtools.common.ssh.components.SshKeyPair> identities) Add a key pair to use for authentication.withPassword
(char[] password) Set the password to use for authentication.withPassword
(String password) Set the password to use for authentication.withPassword
(Optional<String> password) Set the password to use for authentication.Set the password prompt to use for authentication.withPort
(int port) Set the port to use.Set the port to use.withPrivateKeyFile
(File file) Set a private key file to use for authentication.withPrivateKeyFile
(Path file) Set a private key file to use for authentication.withSshContext
(SshClientContext context) Set theSshClientContext
to use.withTarget
(String hostname, int port) Set the hostname and port to use from the provided address.withTarget
(InetSocketAddress address) Set the host and port to use from the provided address.withUsername
(String username) Set the username to use for authentication.withUsername
(Optional<String> username) Set the username to use for authentication.
-
Method Details
-
onConfigure
Set aConsumer
that receives aSshClientContext
when the connection is ready for configuration. You may use this to configure socket options and other advanced settings.- Parameters:
onConfigure
- callback invoked on configuration
-
withPrivateKeyFile
Set a private key file to use for authentication. Internally, this adds aPrivateKeyFileAuthenticator
.- Parameters:
file
- private key file- Returns:
- this for chaining
- Throws:
UncheckedIOException
- on any I/O error or parsing of key
-
withPrivateKeyFile
Set a private key file to use for authentication. Internally, this adds aPrivateKeyFileAuthenticator
.- Parameters:
file
- private key file- Returns:
- this for chaining
- Throws:
UncheckedIOException
- on any I/O error or parsing of key
-
withPassword
Set the password to use for authentication. Internally, this adds aPasswordAuthentication
.- Parameters:
password
- password- Returns:
- this for chaining
-
withPassword
Set the password to use for authentication. Internally, this adds aPasswordAuthentication
.- Parameters:
password
- password- Returns:
- this for chaining
-
withPassword
Set the password to use for authentication. Internally, this adds aPasswordAuthentication
.- Parameters:
password
- password- Returns:
- this for chaining
-
withPasswordPrompt
Set the password prompt to use for authentication. Internally, this adds aPasswordAuthentication
.- Parameters:
prompt
- password prompt- Returns:
- this for chaining
-
addIdentities
public SshClient.SshClientBuilder addIdentities(com.sshtools.common.ssh.components.SshKeyPair... identities) Add on more identities (key pairs) to use for authentication.- Parameters:
identities
- identities- Returns:
- this for chaining
-
addIdentities
public SshClient.SshClientBuilder addIdentities(Collection<com.sshtools.common.ssh.components.SshKeyPair> identities) Add a key pair to use for authentication.- Parameters:
keyPair
- key pair
-
withIdentities
public SshClient.SshClientBuilder withIdentities(com.sshtools.common.ssh.components.SshKeyPair... identities) Set one more identities (key pairs) to use for authentication. Any existing built identities will be replaced.- Parameters:
identities
- identities- Returns:
- this for chaining
-
withIdentities
public SshClient.SshClientBuilder withIdentities(Collection<com.sshtools.common.ssh.components.SshKeyPair> identities) Add a key pair to use for authentication.- Parameters:
keyPair
- key pair
-
addAuthenticators
Add one or moreClientAuthenticator
instances that will be presented to the server one at a time. This will be used by convenience methods such aswithPassword(String)
and TODO XXXXXXXXX- Parameters:
authenticators
- authenticators- Returns:
- this for chaining
-
addAuthenticators
Add one or moreClientAuthenticator
instances that will be presented to the server one at a time. This will be used by convenience methods such aswithPassword(String)
and TODO XXXXXXXXX- Parameters:
authenticators
- authenticators- Returns:
- this for chaining
-
withAuthenticators
Set the list of one or moreClientAuthenticator
instances that will be presented to the server one at a time. This will replace any other built authenticators.- Parameters:
authenticators
- authenticators- Returns:
- this for chaining
-
withAuthenticators
public SshClient.SshClientBuilder withAuthenticators(Collection<ClientAuthenticator> authenticators) Set the list of one or moreClientAuthenticator
instances that will be presented to the server one at a time. This will replace any other built authenticators.- Parameters:
authenticators
- authenticators- Returns:
- this for chaining
-
withConnectTimeout
Set the connection timeout in milliseconds.- Parameters:
connectionTimeout
- connection timeout- Returns:
- this for chaining
-
withConnectTimeout
Set the connection timeout.- Parameters:
milliseconds
- connection timeout- Returns:
- this for chaining
-
withUsername
Set the username to use for authentication. If not provided, guest will be used. A blank or null string will be treated as if the password was not provided.- Parameters:
username
- username- Returns:
- this for chaining
-
withCurrentUsername
Set the username to use for authentication as currently local in local user, what is returned bySystem.getProperty("user.name");
.- Returns:
- this for chaining
-
withUsername
Set the username to use for authentication. If not provided, guest will be used.- Parameters:
username
- username- Returns:
- this for chaining
-
withPort
Set the port to use. If not provided, the default of22
will be used.- Parameters:
port
- port- Returns:
- this for chaining
-
withPort
Set the port to use. If not provided, the default of22
will be used.- Parameters:
port
- port- Returns:
- this for chaining
-
withHost
Set the host to use. May result in name resolution as internallyInetAddress.getHostName()
will be used resolve the address to string.- Parameters:
address
- address- Returns:
- this for chaining
-
withHostname
Set the hostname to use. This must be either a valid hostname or IP address. If not provided,localhost
will be used.- Parameters:
SshClientContext
- sshContext- Returns:
- this for chaining
-
withTarget
Set the host and port to use from the provided address. May result in name resolution as internallyInetAddress.getHostName()
will be used resolve the address to string.- Parameters:
address
- address- Returns:
- this for chaining
-
withTarget
Set the hostname and port to use from the provided address.- Parameters:
hostname
- hostnameport
- port- Returns:
- this for chaining
-
withSshContext
Set theSshClientContext
to use. If not provided, a default implementation will be used.- Parameters:
SshClientContext
- sshContext- Returns:
- this for chaining
-
create
Create a newSshClient.SshClientBuilder
- Returns:
- builder
-
create
public static SshClient.PreConnectedSshClientBuilder create(com.sshtools.common.ssh.SshConnection connection) Create a newSshClient.SshClientBuilder
using an existing connection.- Returns:
- builder
-
build
Build a newSshClient.SshClientBuilder
set.- Returns:
- permissions
- Throws:
com.sshtools.common.ssh.SshException
IOException
-