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 moreClientAuthenticatorinstances that will be presented to the server one at a time.addAuthenticators(Collection<ClientAuthenticator> authenticators) Add one or moreClientAuthenticatorinstances that will be presented to the server one at a time.addIdentities(SshKeyPair... identities) Add on more identities (key pairs) to use for authentication.addIdentities(Collection<SshKeyPair> identities) Add a key pair to use for authentication.build()Build a newSshClient.SshClientBuilderset.static SshClient.SshClientBuildercreate()Create a newSshClient.SshClientBuildercreate(SshConnection connection) Create a newSshClient.SshClientBuilderusing an existing connection.onConfigure(SshClient.OnConfiguration onConfigure) Set aConsumerthat receives aSshClientContextwhen the connection is ready for configuration.withAuthenticators(ClientAuthenticator... authenticators) Set the list of one or moreClientAuthenticatorinstances that will be presented to the server one at a time.withAuthenticators(Collection<ClientAuthenticator> authenticators) Set the list of one or moreClientAuthenticatorinstances 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(SshKeyPair... identities) Set one more identities (key pairs) to use for authentication.withIdentities(Collection<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(File file, PassphrasePrompt prompt) Set a private key file to use for authentication.withPrivateKeyFile(Path file) Set a private key file to use for authentication.withPrivateKeyFile(Path path, PassphrasePrompt prompt) Set a private key file to use for authentication.withPrivateKeyFiles(Collection<File> files) Set multiple private keys from a Path collection.withPrivateKeyFiles(Collection<File> files, PassphrasePrompt prompt) Set a private key file to use for authentication.withPrivateKeyPaths(Collection<Path> paths) Set multiple private keys from a Path collection.withPrivateKeyPaths(Collection<Path> paths, PassphrasePrompt prompt) Set multiple private keys from a Path collection.withSshContext(SshClientContext context) Set theSshClientContextto 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 aConsumerthat receives aSshClientContextwhen 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
-
withPrivateKeyPaths
Set multiple private keys from a Path collection.- Parameters:
paths-- Returns:
-
withPrivateKeyPaths
public SshClient.SshClientBuilder withPrivateKeyPaths(Collection<Path> paths, PassphrasePrompt prompt) Set multiple private keys from a Path collection.- Parameters:
paths-prompt-
-
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. Additionally sets thePassphrasePromptfor a callback to retrieve the keys passphrase if it is encrypted.- Parameters:
file-prompt-- Returns:
-
withPrivateKeyFile
Set a private key file to use for authentication. Internally, this adds aPrivateKeyFileAuthenticator. Additionally sets thePassphrasePromptfor a callback to retrieve the keys passphrase if it is encrypted.- Parameters:
path-prompt-- Returns:
-
withPrivateKeyFiles
Set multiple private keys from a Path collection.- Parameters:
files-- Returns:
-
withPrivateKeyFiles
public SshClient.SshClientBuilder withPrivateKeyFiles(Collection<File> files, PassphrasePrompt prompt) Set a private key file to use for authentication. Internally, this adds aPrivateKeyFileAuthenticator. Additionally sets thePassphrasePromptfor a callback to retrieve the keys passphrase if it is encrypted.- Parameters:
files-prompt-- Returns:
-
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
Add on more identities (key pairs) to use for authentication.- Parameters:
identities- identities- Returns:
- this for chaining
-
addIdentities
Add a key pair to use for authentication.- Parameters:
keyPair- key pair
-
withIdentities
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
Add a key pair to use for authentication.- Parameters:
keyPair- key pair
-
addAuthenticators
Add one or moreClientAuthenticatorinstances 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 moreClientAuthenticatorinstances 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 moreClientAuthenticatorinstances 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 moreClientAuthenticatorinstances 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 of22will be used.- Parameters:
port- port- Returns:
- this for chaining
-
withPort
Set the port to use. If not provided, the default of22will 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,localhostwill 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 theSshClientContextto 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
Create a newSshClient.SshClientBuilderusing an existing connection.- Returns:
- builder
-
build
Build a newSshClient.SshClientBuilderset.- Returns:
- permissions
- Throws:
SshExceptionIOException
-