nodejs-itoolkit
nodejs-itoolkit copied to clipboard
feat: Ability to pass in ssh2 client to transport
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,
});
:wave: Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.