diff --git a/README.md b/README.md index 135dfa1..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'); @@ -18,8 +18,12 @@ var options = { user: 'username', host: 'myServer', port: '22', - path: '~' -} + path: '~', + sshOptions: { + StrictHostKeyChecking: "no", + UserKnownHostsFile: "/dev/null" + } +}; scp.send(options, function (err) { if (err) console.log(err); @@ -27,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`) @@ -43,11 +47,15 @@ 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) + 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. @@ -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) + sshOptions: { + StrictHostKeyChecking: "no" + } }); ```` diff --git a/package.json b/package.json index 40f5c2e..6a91b4c 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,12 @@ "Gabriel Preston ", "Joseph Silvestre ", "appr ", - "Daniel Phatthanan " + "Daniel Phatthanan ", + "Julien Stébenne " ], "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..ac8ea42 100644 --- a/scp.js +++ b/scp.js @@ -6,6 +6,17 @@ var exec = require('child_process').exec; var scp = module.exports = {}; +function buildSshOptions(options) { + 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 */ @@ -15,7 +26,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, ]; @@ -37,7 +48,7 @@ scp.get = 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.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file, options.path ]; diff --git a/test/get.js b/test/get.js index ee6f9fa..dbeda3b 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', + sshOptions: { + StrictHostKeyChecking: 'no' + } }, function () { console.log(arguments); }); diff --git a/test/send.js b/test/send.js index fa414e9..f93ec93 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: '~', + sshOptions: { + StrictHostKeyChecking: 'no', + UserKnownHostsFile: '/dev/null' + } }, function () { console.log(arguments); });