-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (32 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const spawn = require('child_process').spawn;
const Executor = require('@runnerty/module-core').Executor;
class scpExecutor extends Executor {
constructor(process) {
super(process);
}
exec(params) {
const endOptions = {};
const port = params.remotePort || '22';
const password = params.remotePassword ? `sshpass -p '${params.remotePassword}'` : '';
const identityFile = params.identityFile && password === '' ? `-i ${params.identityFile}` : '';
const scpCommand = `${password} scp -P ${port} ${identityFile} ${params.localFile} ${params.remoteUser}@${params.remoteHost}:${params.remoteFilePath}`;
endOptions.command_executed = scpCommand;
const proc = spawn(scpCommand, [], { shell: true });
let stderr = '';
proc.stderr.on('data', chunk => {
stderr += chunk;
});
proc.on('close', (code, signal) => {
if (code) {
endOptions.end = 'error';
endOptions.messageLog = `SCP Error (${scpCommand}): ${signal} / ${stderr}`;
endOptions.err_output = `SCP Error (${scpCommand}): ${signal} / ${stderr}`;
this.end(endOptions);
} else {
this.end();
}
});
}
}
module.exports = scpExecutor;