Skip to content

Commit ef43402

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

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var options = {
1818
user: 'username',
1919
host: 'myServer',
2020
port: '22',
21-
path: '~'
21+
path: '~',
22+
ssh: ["StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null"]
2223
}
2324

2425
scp.send(options, function (err) {
@@ -43,7 +44,8 @@ scp.send({
4344
user: 'username', // username to authenticate as on remote system
4445
host: 'myServer', // remote host to copy to, set up in your ~/.ssh/config
4546
port: '22', // remote port, optional, defaults to '22'
46-
path: '~' // remote path to save to (this would result in a ~/file.txt on myServer)
47+
path: '~', // remote path to save to (this would result in a ~/file.txt on myServer)
48+
ssh: ["StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null"] // additional ssh options (can be an array of options or one string option)
4749
});
4850
````
4951

@@ -61,7 +63,8 @@ scp.get({
6163
user: 'username', // username to authenticate as on remote system
6264
host: 'myServer', // remote host to transfer from, set up in your ~/.ssh/config
6365
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)
66+
path: '~', // local path to save to (this would result in a ~/file.txt on the local machine)
67+
ssh: "StrictHostKeyChecking=no"
6568
});
6669
````
6770

scp.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ var scp = module.exports = {};
1010
* Transfer a file to a remote host
1111
*/
1212
scp.send = function (options, cb) {
13+
var ssh_options = ["ControlMaster=no"]; //callback is not fired if ssh sessions are shared
14+
ssh_options = options.ssh ? ssh_options.concat(options.ssh) : ssh_options;
1315
var command = [
1416
'scp',
1517
'-r',
1618
'-P',
1719
(options.port == undefined ? '22' : options.port),
18-
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
20+
'-o ' + ssh_options.join(' -o '),
1921
options.file,
2022
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.path,
2123
];
@@ -32,12 +34,14 @@ scp.send = function (options, cb) {
3234
* Grab a file from a remote host
3335
*/
3436
scp.get = function (options, cb) {
37+
var ssh_options = ["ControlMaster=no"]; //callback is not fired if ssh sessions are shared
38+
ssh_options = options.ssh ? ssh_options.concat(options.ssh) : ssh_options;
3539
var command = [
3640
'scp',
3741
'-r',
3842
'-P',
3943
(options.port == undefined ? '22' : options.port),
40-
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
44+
'-o ' + ssh_options.join(' -o '),
4145
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file,
4246
options.path
4347
];

test/get.js

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

test/send.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var scp = require('../');
33
scp.send({
44
file: './test/what',
55
host: 'core',
6-
path: '~'
6+
path: '~',
7+
ssh: ["StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null"]
78
}, function () {
89
console.log(arguments);
910
});

0 commit comments

Comments
 (0)