2
我有一個關於ssh的問題。nodejs + ssh2 + nodessh
var Connection = require('ssh2');
var c = new Connection();
c.on('connect', function() {
console.log('Connection :: connect');
});
c.on('ready', function() {
console.log('Connection :: ready');
c.exec('uptime', function(err, stream) {
if (err) throw err;
stream.on('data', function(data, extended) {
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ')
+ data);
});
stream.on('end', function() {
console.log('Stream :: EOF');
});
stream.on('close', function() {
console.log('Stream :: close');
});
stream.on('exit', function(code, signal) {
console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
c.end();
});
});
});
c.on('error', function(err) {
console.log('Connection :: error :: ' + err);
});
c.on('end', function() {
console.log('Connection :: end');
});
c.on('close', function(had_error) {
console.log('Connection :: close');
});
c.connect({
host: 'ip',
port: 22,
username: 'root',
password: 'pass'
});
我,已經盡力啓動它,但它連接到服務器,並跳轉到結束和關閉功能。我檢查了服務器已開啓。我使用ssh2在shell中建立了連接,所以我發現在我的copypaste代碼中必定存在錯誤。我究竟做錯了什麼?