Skip to content

Commit

Permalink
Add additional ssh options
Browse files Browse the repository at this point in the history
  • Loading branch information
tbouchnafa committed Aug 7, 2017
1 parent d45e22e commit 45a3ab5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var options = {
user: 'username',
host: 'myServer',
port: '22',
path: '~'
path: '~',
ssh: ["StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null"]
}

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

Expand All @@ -61,7 +63,8 @@ scp.get({
user: 'username', // username to authenticate as on remote system
host: 'myServer', // remote host to transfer from, set up in your ~/.ssh/config
port: '22', // remote port, optional, defaults to '22'
path: '~' // local path to save to (this would result in a ~/file.txt on the local machine)
path: '~', // local path to save to (this would result in a ~/file.txt on the local machine)
ssh: "StrictHostKeyChecking=no"
});
````

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"name": "scp",
"description": "remote file copy wrapper",
"version": "0.0.4",
"version": "0.0.5",
"repository": {
"type": "git",
"url": "git://github.com/ecto/node-scp.git"
Expand Down
15 changes: 13 additions & 2 deletions scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ var exec = require('child_process').exec;

var scp = module.exports = {};

function buildSshOptions(options) {
result = '';
var ssh_options = options.ssh_options || {}
ssh_options['ControlMaster'] = 'no'
Object.keys(ssh_options).map(function (key) {
result += "-o " + key + '=' + ssh_options[key] + ' '
})
return result.trim();
}
/*
* Transfer a file to a remote host
*/
Expand All @@ -15,7 +24,7 @@ scp.send = function (options, cb) {
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
buildSshOptions(options),
options.file,
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.path,
];
Expand All @@ -32,12 +41,14 @@ scp.send = function (options, cb) {
* Grab a file from a remote host
*/
scp.get = function (options, cb) {
var ssh_options = ["ControlMaster=no"]; //callback is not fired if ssh sessions are shared
ssh_options = options.ssh ? ssh_options.concat(options.ssh) : ssh_options;
var command = [
'scp',
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
buildSshOptions(options),
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file,
options.path
];
Expand Down
5 changes: 4 additions & 1 deletion test/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ var scp = require('../');
scp.get({
file: '~/test',
host: 'core',
path: './test/what'
path: './test/what',
ssh_options: {
StrictHostKeyChecking: 'no'
}
}, function () {
console.log(arguments);
});
6 changes: 5 additions & 1 deletion test/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ var scp = require('../');
scp.send({
file: './test/what',
host: 'core',
path: '~'
path: '~',
ssh_options: {
StrictHostKeyChecking: 'no',
UserKnownHostsFile: '/dev/null'
}
}, function () {
console.log(arguments);
});

0 comments on commit 45a3ab5

Please sign in to comment.