nodejs-itoolkit icon indicating copy to clipboard operation
nodejs-itoolkit copied to clipboard

feat: Ability to pass in ssh2 client to transport

Open abmusse opened this issue 5 years ago • 1 comments

Part of #315

Here is an example on how this could be used:

/**
 * Example using an existing ssh2 client with itoolkit's ssh transport
 */

const { Connection, CommandCall } = require('itoolkit');
const { Client } = require('ssh2');
const { parseString } = require('xml2js');

const client = new Client();

// add ready listener
// then call itoolkit after client is connected and ready
client.on('ready', () => {
  const connection = new Connection({
    transport: 'ssh',
    transportOptions: {
      sshClient: client,
    },
  });

  const command = new CommandCall({ type: 'cl', command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)' });

  connection.add(command);
  connection.run((error, xmlOutput) => {
    if (error) {
      throw error;
    }
    parseString(xmlOutput, (parseError, result) => {
      if (parseError) {
        throw parseError;
      }
      console.log(JSON.stringify(result));
    });
    // user closes the connection as needed
    client.end();
    client.destroy();
  });
});

client.connect({
  host: process.env.HOST,
  username: process.env.USER,
  password: process.env.PASS,
});

abmusse avatar Jan 15 '21 20:01 abmusse

:wave: Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

github-actions[bot] avatar Feb 20 '21 00:02 github-actions[bot]