I have an issue with ssh2 library in Node.js.
I'm trying to run a command on some host in ssh, using this libaray. The host's response may be long, so when it cross the 4096 length of chars in the respose string, it stops the data streaming, so I don't get the whole answer, but only the 4096 first chars.
This is my sshService.js, where I calls the exec function, with the command string to run:
const Client = require('ssh2').Client;
const exec = (command) => {
const conn = new Client();
return new Promise((resolve, reject) => {
conn.on('ready', () => {
let result = [];
conn.exec(command, (err, stram) => {
if (err) throw err;
stream
.on('close', () => { conn.end(); resolve(result); })
.on('data', async (data) => { result.push(await data.toString()); })
.stderr.on('data', (data) => { reject(data.toString()); })
})
}).connect(host: HOST_IP, port: 22, username: USERNAME, password: PASSWORD);
conn.on('error', err => { conn.end(); reject(err); return; });
})
}