简体   繁体   English

节点,SSh2服务器等待输入

[英]Node , SSh2 Server waiting for input

I am currently building a Web based SSH client. 我目前正在构建基于Web的SSH客户端。 I am using node and SSH2 module to connect to Linux machine . 我正在使用节点和SSH2模块连接到Linux计算机。 The issue is trying to identify when the server is waiting for a response from the client say "sudo" . 问题是试图确定服务器何时等待客户端说“ 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. 基本上,您必须缓冲流输出并继续在缓冲区中搜索期望的(sudo)提示,或者使用类似streamsearch的模块来在流中搜索特定的字符串,而无需显式缓冲和连续搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM