Class SshClient.SshClientBuilder

java.lang.Object
com.sshtools.client.SshClient.SshClientBuilder
Enclosing class:
SshClient

public static final class SshClient.SshClientBuilder extends Object
  • Method Details

    • onConfigure

      public SshClient.SshClientBuilder onConfigure(SshClient.OnConfiguration onConfigure)
      Set a Consumer that receives a SshClientContext 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

      public SshClient.SshClientBuilder withPrivateKeyFile(Path file)
      Set a private key file to use for authentication. Internally, this adds a PrivateKeyFileAuthenticator.
      Parameters:
      file - private key file
      Returns:
      this for chaining
      Throws:
      UncheckedIOException - on any I/O error or parsing of key
    • withPrivateKeyFile

      public SshClient.SshClientBuilder withPrivateKeyFile(File file)
      Set a private key file to use for authentication. Internally, this adds a PrivateKeyFileAuthenticator.
      Parameters:
      file - private key file
      Returns:
      this for chaining
      Throws:
      UncheckedIOException - on any I/O error or parsing of key
    • withPassword

      public SshClient.SshClientBuilder withPassword(char[] password)
      Set the password to use for authentication. Internally, this adds a PasswordAuthentication.
      Parameters:
      password - password
      Returns:
      this for chaining
    • withPassword

      public SshClient.SshClientBuilder withPassword(String password)
      Set the password to use for authentication. Internally, this adds a PasswordAuthentication.
      Parameters:
      password - password
      Returns:
      this for chaining
    • withPassword

      public SshClient.SshClientBuilder withPassword(Optional<String> password)
      Set the password to use for authentication. Internally, this adds a PasswordAuthentication.
      Parameters:
      password - password
      Returns:
      this for chaining
    • withPasswordPrompt

      Set the password prompt to use for authentication. Internally, this adds a PasswordAuthentication.
      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

      public SshClient.SshClientBuilder addAuthenticators(ClientAuthenticator... authenticators)
      Add one or more ClientAuthenticator instances that will be presented to the server one at a time. This will be used by convenience methods such as withPassword(String) and TODO XXXXXXXXX
      Parameters:
      authenticators - authenticators
      Returns:
      this for chaining
    • addAuthenticators

      public SshClient.SshClientBuilder addAuthenticators(Collection<ClientAuthenticator> authenticators)
      Add one or more ClientAuthenticator instances that will be presented to the server one at a time. This will be used by convenience methods such as withPassword(String) and TODO XXXXXXXXX
      Parameters:
      authenticators - authenticators
      Returns:
      this for chaining
    • withAuthenticators

      public SshClient.SshClientBuilder withAuthenticators(ClientAuthenticator... authenticators)
      Set the list of one or more ClientAuthenticator 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 more ClientAuthenticator 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

      public SshClient.SshClientBuilder withConnectTimeout(long connectTimeout)
      Set the connection timeout in milliseconds.
      Parameters:
      connectionTimeout - connection timeout
      Returns:
      this for chaining
    • withConnectTimeout

      public SshClient.SshClientBuilder withConnectTimeout(Duration connectTimeout)
      Set the connection timeout.
      Parameters:
      milliseconds - connection timeout
      Returns:
      this for chaining
    • withUsername

      public SshClient.SshClientBuilder withUsername(String username)
      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

      public SshClient.SshClientBuilder withCurrentUsername(String username)
      Set the username to use for authentication as currently local in local user, what is returned by System.getProperty("user.name");.
      Returns:
      this for chaining
    • withUsername

      public SshClient.SshClientBuilder withUsername(Optional<String> username)
      Set the username to use for authentication. If not provided, guest will be used.
      Parameters:
      username - username
      Returns:
      this for chaining
    • withPort

      public SshClient.SshClientBuilder withPort(int port)
      Set the port to use. If not provided, the default of 22 will be used.
      Parameters:
      port - port
      Returns:
      this for chaining
    • withPort

      public SshClient.SshClientBuilder withPort(Optional<Integer> port)
      Set the port to use. If not provided, the default of 22 will be used.
      Parameters:
      port - port
      Returns:
      this for chaining
    • withHost

      public SshClient.SshClientBuilder withHost(InetAddress address)
      Set the host to use. May result in name resolution as internally InetAddress.getHostName() will be used resolve the address to string.
      Parameters:
      address - address
      Returns:
      this for chaining
    • withHostname

      public SshClient.SshClientBuilder withHostname(String hostname)
      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

      public SshClient.SshClientBuilder withTarget(InetSocketAddress address)
      Set the host and port to use from the provided address. May result in name resolution as internally InetAddress.getHostName() will be used resolve the address to string.
      Parameters:
      address - address
      Returns:
      this for chaining
    • withTarget

      public SshClient.SshClientBuilder withTarget(String hostname, int port)
      Set the hostname and port to use from the provided address.
      Parameters:
      hostname - hostname
      port - port
      Returns:
      this for chaining
    • withSshContext

      public SshClient.SshClientBuilder withSshContext(SshClientContext context)
      Set the SshClientContext to use. If not provided, a default implementation will be used.
      Parameters:
      SshClientContext - sshContext
      Returns:
      this for chaining
    • create

      public static SshClient.SshClientBuilder create()
      Returns:
      builder
    • create

      public static SshClient.PreConnectedSshClientBuilder create(com.sshtools.common.ssh.SshConnection connection)
      Create a new SshClient.SshClientBuilder using an existing connection.
      Returns:
      builder
    • build

      public SshClient build() throws IOException, com.sshtools.common.ssh.SshException
      Returns:
      permissions
      Throws:
      com.sshtools.common.ssh.SshException
      IOException