我正在尝试使用npm中的ssh2来建立ssh连接并远程登录到计算机。该代码对于Windows到Linux / MacOS的连接正常,但是对于Windows到Windows的连接则无效(错误屏幕截图已附加)。我确实找到了与agent和agentForward参数相关的内容,可能会导致问题,但找不到解决方案。节点版本:8.11.2
任何帮助,将不胜感激!谢谢!
代码如下:
app.get("/",function(req,res)
{
var conn = new Client();
conn.on('ready', function()
{
console.log('Client :: ready');
conn.exec('systeminfo', function(err, stream)
{//system_profiler SPHardwareDataType, systeminfo
if (err) console.log(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: '127.0.0.1',
port: 22,
username: 'inspiron',
privateKey: require('fs').readFileSync('C:/Users/inspiron/Downloads/private_key.ppk')
});
res.send(str);
});
这是错误消息:
答案 0 :(得分:0)
我也有类似的问题。
library(dplyr)
library(tidyr)
dt %>%
gather(key, value, -Date, na.rm = TRUE) %>%
count(Date, value) %>%
spread(value, n, fill = 0)
# Date `5` `6` `7`
# <dbl> <dbl> <dbl> <dbl>
#1 1 2 1 0
#2 2 0 2 2
尽管我增加了一些延迟,但它以某种方式起作用。
events.js:183
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at _errnoException (util.js:992:11)
at TCP.onread (net.js:618:25)
添加一些延迟或try-catch语句;也与“ stream.on('data',function(data){...
stream.on('close', function(code, signal){
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
//extra lines of code here..
conn.end();
}
答案 1 :(得分:0)
我不得不放弃上述方法,即使用ssh2,因为我找不到面对错误的解决方案。
我要做的是运行Powershell脚本: