I want to execute a script that is in a folder in a server machine, over my local machine. I use ssh2 to create the connection between server and local machine.
const { Client } = require('ssh2');
const fs = require("fs");
const path = require("path");
function connectIn(req, res) {
console.log('ENTRANDO EN CONNECTION SSH', req.body);
const repoFile = "cd C:\repoScripts\shutdown.bat";
const conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.exec('type /repoScript/shutdown.bat', (err, stream) => {
if (err) throw err;
stream.on('close', (code, signal) => {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', (data) => {
console.log('STDOUT: ' + data);
}).stderr.on('data', (data) => {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '192.168.1.130',
port: 22,
username: 'ddaud',
password: 'Mraixa0319T'
});
}
module.exports = { connectIn }
the connect data are the server and i can connect and make a dir or whatever in the server, but i can not find and execute the script over my local machine.
Someone has some idea? thanks