[英]Is there a synchronous equivalent for the Client method "exec" in ssh2 for node js?
我已经在节点 js 中使用 ssh2 连接到远程机器。
现在我想在远程机器上同步运行命令。
var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', function() {
console.log('Client :: ready');
conn.exec('uptime', function(err, stream) {
if (err) throw err;
stream.on('close', function(code, signal) {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', function(data) {
console.log('STDOUT: ' + data);
}).stderr.on('data', function(data) {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '192.168.100.100',
port: 22,
username: 'frylock',
privateKey: require('fs').readFileSync('/here/is/my/key')
});
这样我可以以异步方式执行它。 如果有任何 function 等效于“exec”,即同步。
使用 conn.shell 代替 conn.exec。 使用 shell 方法,您可以启动交互式 shell session。
这里有一个例子:
https://github.com/mscdex/ssh2#start-an-interactive-shell-session
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.