-
Notifications
You must be signed in to change notification settings - Fork 26
/
scp.js
51 lines (48 loc) · 1.18 KB
/
scp.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
43
44
45
46
47
48
49
50
51
/*
* node-scp
*/
var exec = require('child_process').exec;
var scp = module.exports = {};
/*
* Transfer a file to a remote host
*/
scp.send = function (options, cb) {
var command = [
'scp',
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
options.file,
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.path,
];
exec(command.join(' '), function (err, stdout, stderr) {
if (cb) {
cb(err, stdout, stderr);
} else {
if (err) throw new Error(err);
}
});
}
/*
* Grab a file from a remote host
*/
scp.get = function (options, cb) {
var command = [
'scp',
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file,
options.path
];
exec(command.join(' '), function (err, stdout, stderr) {
if (cb) {
cb(err, stdout, stderr);
} else {
if (err) throw new Error(err);
}
});
}