Skip to content

Commit 25846f6

Browse files
author
tbouchnafa
committed
Add additional ssh options
1 parent d45e22e commit 25846f6

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ var options = {
1818
user: 'username',
1919
host: 'myServer',
2020
port: '22',
21-
path: '~'
21+
path: '~',
22+
ssh_options: {
23+
StrictHostKeyChecking: "no",
24+
UserKnownHostsFile: "/dev/null"
25+
}
2226
}
2327

2428
scp.send(options, function (err) {
@@ -43,7 +47,11 @@ scp.send({
4347
user: 'username', // username to authenticate as on remote system
4448
host: 'myServer', // remote host to copy to, set up in your ~/.ssh/config
4549
port: '22', // remote port, optional, defaults to '22'
46-
path: '~' // remote path to save to (this would result in a ~/file.txt on myServer)
50+
path: '~', // remote path to save to (this would result in a ~/file.txt on myServer)
51+
ssh_options: {
52+
StrictHostKeyChecking: "no",
53+
UserKnownHostsFile: "/dev/null"
54+
} // additional ssh options
4755
});
4856
````
4957

@@ -61,7 +69,10 @@ scp.get({
6169
user: 'username', // username to authenticate as on remote system
6270
host: 'myServer', // remote host to transfer from, set up in your ~/.ssh/config
6371
port: '22', // remote port, optional, defaults to '22'
64-
path: '~' // local path to save to (this would result in a ~/file.txt on the local machine)
72+
path: '~', // local path to save to (this would result in a ~/file.txt on the local machine)
73+
ssh_options: {
74+
StrictHostKeyChecking: "no"
75+
}
6576
});
6677
````
6778

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"name": "scp",
1313
"description": "remote file copy wrapper",
14-
"version": "0.0.4",
14+
"version": "0.0.5",
1515
"repository": {
1616
"type": "git",
1717
"url": "git://github.com/ecto/node-scp.git"

scp.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ var exec = require('child_process').exec;
66

77
var scp = module.exports = {};
88

9+
function buildSshOptions(options) {
10+
result = '';
11+
var ssh_options = options.ssh_options || {}
12+
ssh_options['ControlMaster'] = 'no'
13+
Object.keys(ssh_options).map(function (key) {
14+
result += "-o " + key + '=' + ssh_options[key] + ' '
15+
})
16+
return result.trim();
17+
}
918
/*
1019
* Transfer a file to a remote host
1120
*/
@@ -15,7 +24,7 @@ scp.send = function (options, cb) {
1524
'-r',
1625
'-P',
1726
(options.port == undefined ? '22' : options.port),
18-
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
27+
buildSshOptions(options),
1928
options.file,
2029
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.path,
2130
];
@@ -32,12 +41,14 @@ scp.send = function (options, cb) {
3241
* Grab a file from a remote host
3342
*/
3443
scp.get = function (options, cb) {
44+
var ssh_options = ["ControlMaster=no"]; //callback is not fired if ssh sessions are shared
45+
ssh_options = options.ssh ? ssh_options.concat(options.ssh) : ssh_options;
3546
var command = [
3647
'scp',
3748
'-r',
3849
'-P',
3950
(options.port == undefined ? '22' : options.port),
40-
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
51+
buildSshOptions(options),
4152
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file,
4253
options.path
4354
];

test/get.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ var scp = require('../');
33
scp.get({
44
file: '~/test',
55
host: 'core',
6-
path: './test/what'
6+
path: './test/what',
7+
ssh_options: {
8+
StrictHostKeyChecking: 'no'
9+
}
710
}, function () {
811
console.log(arguments);
912
});

test/send.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ var scp = require('../');
33
scp.send({
44
file: './test/what',
55
host: 'core',
6-
path: '~'
6+
path: '~',
7+
ssh_options: {
8+
StrictHostKeyChecking: 'no',
9+
UserKnownHostsFile: '/dev/null'
10+
}
711
}, function () {
812
console.log(arguments);
913
});

0 commit comments

Comments
 (0)