My aim is to make a web application that allows it's user to connect to an SSH server remotely, i.e. without installing an SSH client on their computer. So this means my server will be an intermediate interface between the user and their SSH server/s.
I found an SSH2 module for node: https://github.com/mscdex/ssh2
I figured the most appropriate method of connecting was using the shell() method.
The following is a basic attempt to get a shell working.
var Connection = require('ssh2');
var c = new Connection();
c.on('ready', function() {
c.shell(onShell);
});
var onShell = function(err, stream) {
if (err != null) {
console.log('error: ' + err);
}
stream.on('readable', function() {
var chunk;
while (null !== (chunk = stream.read())) {
console.log('got %d bytes of data', chunk.length);
}
});
stream.write('ls\r\n');
console.log('Shell');
}
c.connect({
host: 'localhost',
port: 22,
username: 'matt',
password: 'password'
});
It connects fine, and there are no errors, but the "got %d bytes of data" does not show. How can I fix this?
Furthermore would this method be sensible in a large scale application with potentially many simultaneous different connections?
on('data')?