From 25846f616fc872093e16d990e2a1271fe2a12d88 Mon Sep 17 00:00:00 2001 From: tbouchnafa Date: Mon, 7 Aug 2017 12:41:30 +0200 Subject: [PATCH 1/3] Add additional ssh options --- README.md | 17 ++++++++++++++--- package.json | 2 +- scp.js | 15 +++++++++++++-- test/get.js | 5 ++++- test/send.js | 6 +++++- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 135dfa1..363aa23 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,11 @@ var options = { user: 'username', host: 'myServer', port: '22', - path: '~' + path: '~', + ssh_options: { + StrictHostKeyChecking: "no", + UserKnownHostsFile: "/dev/null" + } } scp.send(options, function (err) { @@ -43,7 +47,11 @@ 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_options: { + StrictHostKeyChecking: "no", + UserKnownHostsFile: "/dev/null" + } // additional ssh options }); ```` @@ -61,7 +69,10 @@ 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_options: { + StrictHostKeyChecking: "no" + } }); ```` diff --git a/package.json b/package.json index 40f5c2e..0d6e739 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scp.js b/scp.js index 9c78819..21b14bf 100644 --- a/scp.js +++ b/scp.js @@ -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 */ @@ -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, ]; @@ -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 ]; diff --git a/test/get.js b/test/get.js index ee6f9fa..235f370 100644 --- a/test/get.js +++ b/test/get.js @@ -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); }); diff --git a/test/send.js b/test/send.js index fa414e9..af3db7b 100644 --- a/test/send.js +++ b/test/send.js @@ -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); }); From 0564bde782c3a1740e12733b7817372f56cf0367 Mon Sep 17 00:00:00 2001 From: Julien Stebenne Date: Fri, 8 Mar 2019 23:28:30 -0500 Subject: [PATCH 2/3] Default option handling --- README.md | 28 ++++++++++++++-------------- scp.js | 18 +++++++++--------- test/get.js | 2 +- test/send.js | 6 +++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 363aa23..698514e 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ SCP (secure file copy) wrapper for node.js ![scp](http://i.imgur.com/RrUKV.gif) -##install +## install npm install scp -##usage +## usage ````javascript var scp = require('scp'); @@ -19,11 +19,11 @@ var options = { host: 'myServer', port: '22', path: '~', - ssh_options: { - StrictHostKeyChecking: "no", - UserKnownHostsFile: "/dev/null" + sshOptions: { + StrictHostKeyChecking: "no", + UserKnownHostsFile: "/dev/null" } -} +}; scp.send(options, function (err) { if (err) console.log(err); @@ -31,9 +31,9 @@ scp.send(options, function (err) { }); ```` -##methods +## methods -###scp.send(options, cb) +### scp.send(options, cb) Send a file to a remote host (in your `~/.ssh/config`) @@ -48,14 +48,14 @@ scp.send({ 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) - ssh_options: { - StrictHostKeyChecking: "no", - UserKnownHostsFile: "/dev/null" + sshOptions: { + StrictHostKeyChecking: "no", + UserKnownHostsFile: "/dev/null" } // additional ssh options }); ```` -###scp.get(options, cb) +### scp.get(options, cb) Transfer a file from a remote host (in your `~/.ssh/config`) to the current computer. @@ -70,8 +70,8 @@ scp.get({ 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) - ssh_options: { - StrictHostKeyChecking: "no" + sshOptions: { + StrictHostKeyChecking: "no" } }); ```` diff --git a/scp.js b/scp.js index 21b14bf..ac8ea42 100644 --- a/scp.js +++ b/scp.js @@ -7,13 +7,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(); + var result = ''; + var defaults = { + ControlMaster: 'no' + }; + var sshOptions = Object.assign({}, defaults, options.sshOptions); + Object.keys(sshOptions).map(function (key) { + result += "-o " + key + '=' + sshOptions[key] + ' '; + }); + return result.trim(); } /* * Transfer a file to a remote host @@ -41,8 +43,6 @@ 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', diff --git a/test/get.js b/test/get.js index 235f370..dbeda3b 100644 --- a/test/get.js +++ b/test/get.js @@ -4,7 +4,7 @@ scp.get({ file: '~/test', host: 'core', path: './test/what', - ssh_options: { + sshOptions: { StrictHostKeyChecking: 'no' } }, function () { diff --git a/test/send.js b/test/send.js index af3db7b..f93ec93 100644 --- a/test/send.js +++ b/test/send.js @@ -4,9 +4,9 @@ scp.send({ file: './test/what', host: 'core', path: '~', - ssh_options: { - StrictHostKeyChecking: 'no', - UserKnownHostsFile: '/dev/null' + sshOptions: { + StrictHostKeyChecking: 'no', + UserKnownHostsFile: '/dev/null' } }, function () { console.log(arguments); From 2cb52dffbe9249560e666b6ac0740f5efef15271 Mon Sep 17 00:00:00 2001 From: Julien Stebenne Date: Fri, 8 Mar 2019 23:42:35 -0500 Subject: [PATCH 3/3] Added contributor info --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d6e739..6a91b4c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "Gabriel Preston ", "Joseph Silvestre ", "appr ", - "Daniel Phatthanan " + "Daniel Phatthanan ", + "Julien Stébenne " ], "name": "scp", "description": "remote file copy wrapper",