Class RemoteCommandRunner

  • All Implemented Interfaces:
    CommandRunner

    public class RemoteCommandRunner
    extends Object
    implements CommandRunner
    Run a command on a remote server using the ssh protocol connecting to a sshd. Only user name and password authentication is supported.
    • Method Detail

      • initialize

        public void initialize()
                        throws IOException
        Open a session to a remote sshd at the configured host and port. The client authenticates with the sshd using the configured user name and password. If authentication fails and network communication errors occur, an IOException is thrown.
        Specified by:
        initialize in interface CommandRunner
        Throws:
        IOException - thrown if authentication fails or networking problems occur
      • runCommand

        public int runCommand​(List<String> args,
                              InputStream stdIn,
                              OutputStream stdOut,
                              OutputStream stdErr)
                       throws IOException
        Submits the given command to the connected session. The standard output and standard error are captured in the given output streams. The exit code of the shell command is provided as the return value. All resources for the opened command channel are released before returning. This method can be invoked multiple times as needed on an open client session.
        Specified by:
        runCommand in interface CommandRunner
        Parameters:
        command - the shell command to execute
        stdOut - standard output of the command is captured here
        stdErr - standard error of the shell command is captured here
        Returns:
        exit code of the shell command
        Throws:
        IOException - thrown if any error occur communicating with the remote sshd