I'm attempting to make an interactive ssh session where I can send bash cmds and get back the result.
The following works:
var SSH2Promise = require('ssh2-promise');
var sshconfig = {
host: '192.168.1.142',
username: 'root',
password: 'pass'
}
var ssh = new SSH2Promise(sshconfig);
ssh.connect().then(() => {console.log("Connection established")})
But what I really want to do is something like:
var ssh_socket
ssh.shell().then((socket) => {
ssh_socket = socket
socket.on('data', (data) => {
console.log("ssh data: " + data)
})
socket.write("echo ssh shell connected\n")
})
ssh_socket.write("ls\n")
My call to ssh.shell shows nothing but I expected to see
"ssh data: ssh shell connected"
in the console. Furthermore, after this initialization, I hope to be able to send in many commands, a la
ssh_socket.write("ls\n")
and see their results.