I am currently building a Web based SSH client. I am using node and SSH2 module to connect to Linux machine . The issue is trying to identify when the server is waiting for a response from the client say "sudo" .
this.onWsMessage = function(packet) { log('Message Received from '); if (cmd != '') { log('----------------------------------------->' + cmd); source[this.getId()].sshStream.write(cmd + '\\n'); } }; var client = clients[cid]; sshClient .on('ready', function() { console.log('CONNECTED'); sshClient.shell({pty: true}, function(err, stream) { _shellHandler(err, stream, client); }); }) .on('error', function(err) { console.log('ERROR', err); }) .connect(serverInfo); } function _shellHandler(err, stream, client) { source[client.getId()].sshStream = stream; stream .on('close', function() { log('ssh connection close'); //sshClient.end(); this._client.end(); }) .on('data', function(data) { console.log(stream); var msg = data.toString().replace(msgPattern, ''); this.sendUTF(msg, 'ssh'); }.bind(client)); }
I have been going through the documentation and i was unable to identify any event that trigger as a result.
There is no easy way to do this. Basically you have to either buffer stream output and continually search that buffer for expected (sudo) prompts or use a module like streamsearch
to search the stream for a particular string without explicitly buffering and continual searching.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.