Module bus.extra

Class Connector

java.lang.Object
org.miaixz.bus.extra.ssh.Connector

public class Connector extends Object
Represents a connector object that provides basic connection information for services like SSH, FTP, etc. This class encapsulates the following details:
  • host: The hostname or IP address of the server.
  • port: The port number for the connection.
  • user: The username for authentication (defaults to "root").
  • password: The password for authentication.
  • timeout: The connection timeout in milliseconds.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Connector

      public Connector()
      Constructs a new, empty Connector instance.
    • Connector

      public Connector(String host, int port, String user, String password, long timeout)
      Constructs a new Connector instance with specified host, port, user, password, and timeout.
      Parameters:
      host - The hostname or IP address of the server.
      port - The port number for the connection.
      user - The username for authentication.
      password - The password for authentication.
      timeout - The connection timeout duration in milliseconds; a value of 0 may indicate the default timeout.
  • Method Details

    • of

      public static Connector of()
      Creates a new Connector instance with default parameters. This is useful for a builder-style pattern of object creation.
      Returns:
      A new, empty Connector instance.
    • of

      public static Connector of(String host, int port, String user, String password)
      Creates a new Connector instance with specified host, port, user, and password. The timeout is set to its default value (0).
      Parameters:
      host - The hostname or IP address of the server.
      port - The port number for the connection.
      user - The username for authentication.
      password - The password for authentication.
      Returns:
      A new Connector instance initialized with the provided details.
    • of

      public static Connector of(String host, int port, String user, String password, long timeout)
      Creates a new Connector instance with specified host, port, user, password, and timeout.
      Parameters:
      host - The hostname or IP address of the server.
      port - The port number for the connection.
      user - The username for authentication.
      password - The password for authentication.
      timeout - The connection timeout duration in milliseconds; a value of 0 may indicate the default timeout.
      Returns:
      A new Connector instance initialized with the provided details.
    • getHost

      public String getHost()
      Retrieves the hostname or IP address of the server.
      Returns:
      The hostname as a String.
    • setHost

      public Connector setHost(String host)
      Sets the hostname or IP address of the server.
      Parameters:
      host - The hostname to set.
      Returns:
      This Connector instance, allowing for method chaining.
    • getPort

      public int getPort()
      Retrieves the port number for the connection.
      Returns:
      The port number.
    • setPort

      public Connector setPort(int port)
      Sets the port number for the connection.
      Parameters:
      port - The port number to set.
      Returns:
      This Connector instance, allowing for method chaining.
    • getUser

      public String getUser()
      Retrieves the username for authentication.
      Returns:
      The username as a String.
    • setUser

      public Connector setUser(String name)
      Sets the username for authentication.
      Parameters:
      name - The username to set.
      Returns:
      This Connector instance, allowing for method chaining.
    • getPassword

      public String getPassword()
      Retrieves the password for authentication.
      Returns:
      The password as a String.
    • setPassword

      public Connector setPassword(String password)
      Sets the password for authentication.
      Parameters:
      password - The password to set.
      Returns:
      This Connector instance, allowing for method chaining.
    • getTimeout

      public long getTimeout()
      Retrieves the connection timeout duration in milliseconds.
      Returns:
      The connection timeout duration.
    • setTimeout

      public Connector setTimeout(long timeout)
      Sets the connection timeout duration in milliseconds.
      Parameters:
      timeout - The connection timeout duration to set.
      Returns:
      This Connector instance, allowing for method chaining.
    • toString

      public String toString()
      Returns a string representation of the connector object. This method is intended for logging and debugging purposes only.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the connector's properties.