src/ssh-client.js
/**
     * Connects to the remote host, and executes the specified command(s) on it
     * sequentially. Execution will be aborted if any of the commands fail.
     *
     * @param {String|Array} commands The commands to execute on the remote host.
     *
     * @return {Promise<SshExecutionResults>} A promise that will be resolved
     *         with an object that defines the results of execution of the
     *         commands. Note that the promise will be resolved even if command
     *         execution fails. Promise rejection implies a general failure,
     *         such as connection errors, etc.
     */
Connects to the remote host, and executes the specified command(s) on it
sequentially. Execution will be aborted if any of the commands fail.

@param {String|Array} commands The commands to execute on the remote host.

@return {Promise} A promise that will be resolved
with an object that defines the results of execution of the
commands. Note that the promise will be resolved even if command
execution fails. Promise rejection implies a general failure,
such as connection errors, etc.
Connects to the remote host and executes the specified command ( s ) on it sequentially . Execution will be aborted if any of the commands fail . @param { String|Array } commands The commands to execute on the remote host . @return { Promise } A promise that will be resolved with an object that defines the results of execution of the commands . Note that the promise will be resolved even if command execution fails . Promise rejection implies a general failure such as connection errors etc .
run(commands) {
        if (_argValidator.checkString(commands, 1)) {
            commands = [commands];
        }
        _argValidator.checkArray(commands, 'Invalid command(s) (arg #1)');
        const execResult = {
            commandCount: commands.length,
            successCount: 0,
            failureCount: 0,
            results: [],
        };
        return this.getConnectionOptions().then((connOpts) => {
            return new Promise((resolve, reject) => {
                const client = new _ssh2.Client();
                client
                    .on('ready', () => {
                        this.logger.trace('Connected to remote host', {
                            host: this._host,
                            username: this._username,
                        });
                        this._runCommandSet(client, commands)
                            .then((results) => {
                                results.forEach((result) => {
                                    if (result.success) {
                                        execResult.successCount++;
                                    } else {
                                        execResult.failureCount++;
                                    }
                                });
                                execResult.results = results;
                                resolve(execResult);
                            })
                            .finally((execResult) => {
                                resolve(execResult);
                                client.end();
                            });
                    })
                    .on('error', (err) => {
                        this.logger.error(
                            err,
                            'Fatal error executing commands on remote host'
                        );
                        client.end();
                        reject(err);
                    })
                    .connect(connOpts);
            });
        });
    }
run ( commands ) { if ( _argValidator . checkString ( commands , 1 ) ) { commands = [ commands ] ; } _argValidator . checkArray ( commands , 'Invalid command(s) (arg #1)' ) ; const execResult = { commandCount : commands . length , successCount : 0 , failureCount : 0 , results : [ ] , } ; return this . getConnectionOptions ( ) . then ( ( connOpts ) => { return new Promise ( ( resolve , reject ) => { const client = new _ssh2 . Client ( ) ; client . on ( 'ready' , ( ) => { this . logger . trace ( 'Connected to remote host' , { host : this . _host , username : this . _username , } ) ; this . _runCommandSet ( client , commands ) . then ( ( results ) => { results . forEach ( ( result ) => { if ( result . success ) { execResult . successCount ++ ; } else { execResult . failureCount ++ ; } } ) ; execResult . results = results ; resolve ( execResult ) ; } ) . finally ( ( execResult ) => { resolve ( execResult ) ; client . end ( ) ; } ) ; } ) . on ( 'error' , ( err ) => { this . logger . error ( err , 'Fatal error executing commands on remote host' ) ; client . end ( ) ; reject ( err ) ; } ) . connect ( connOpts ) ; } ) ; } ) ; }
Connects to the remote host, and executes the specified command(s) on it
 sequentially.
Connects to the remote host and executes the specified command ( s ) on it sequentially .