Class SshConnection

    • Constructor Detail

      • SshConnection

        public SshConnection​(SshConnection.SshConfigurator sshSessionSupplier)
        Create a new SshConnection.

        It automatically opens an SSH connection for forwarding.

        Parameters:
        sshSessionSupplier - function that fills the login information
    • Method Detail

      • addReversePortForwarding

        public int addReversePortForwarding​(int localPort)
        Add a reverse port forwarding.
        Parameters:
        localPort - local port to expose
        Returns:
        port number on the server
      • addForwardPortForwarding

        public int addForwardPortForwarding​(int remotePort)
        Add a forward port forwarding.
        Parameters:
        remotePort - port of the the server to connect to
        Returns:
        local port
      • addForwardPortForwarding

        public int addForwardPortForwarding​(int remotePort,
                                            String targetHost)
        Add a forward port forwarding.
        Parameters:
        remotePort - port of the the server to connect to
        targetHost - the host to forward the request to
        Returns:
        local port
      • runCommandAsRoot

        public SshExecution runCommandAsRoot​(String command)
        Run a shell command as root.

        This is a synchronous method. It will block until the command is finished.

        Parameters:
        command - command to run
        Returns:
        command output (stdout)
      • runCommand

        public SshExecution runCommand​(String command)
        Run a shell command.
        Parameters:
        command - command to run
        Returns:
        ssh execution
      • findFreePortOnServer

        public int findFreePortOnServer()
        Find a free port on the server.
        Returns:
        free port number