I installed openssh on my remote windows server and tested it with putty.Now I want to connect to remote server through node.js , hence installed one package "simple-ssh". This package is also working fine with remote linux server but throws error with windows server.
here is my code file,
var SSH = require('simple-ssh');
var ssh;
ssh = new SSH({
host: 'XXX.XXX.XX.101',
user: 'username',
pass: 'password'
});
var command = 'typeperf "\\Processor(_Total)\\% Processor Time"'
console.log('command :'+command)
ssh.exec(command, {
out: function(stdout) {
console.log(stdout);
}
}).start();
ssh.on('error', function(err) {
console.log('something went wrong.');
console.log(err);
ssh.end();
});
And below error i get in console,
command :typeperf "\Processor(_Total)\% Processor Time"
something went wrong.
{ Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read',
level: 'client-socket' }
please note, it works when i execute with putty session or when i put var command = 'ping -t XXX.XXX.XX.101'
, but not with var command = 'typeperf "\\Processor(_Total)\\% Processor Time"'
through node.js script. please help to resolve this issue as i have been struggling for weeks.
Many thanks in advance.
I have solved the problem myself. After putting lots of effort and hit & trials, i came to know that it was mainly because of handling double quotations in input string. I handled this by putting escape characters before double quotations and problem got resolved.
I changed
to
And it worked. :-)