Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional ssh options #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ var options = {
user: 'username',
host: 'myServer',
port: '22',
path: '~'
path: '~',
ssh_options: {
StrictHostKeyChecking: "no",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these examples use a different indentation from the rest of the file

UserKnownHostsFile: "/dev/null"
}
}

scp.send(options, function (err) {
Expand All @@ -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
});
````

Expand All @@ -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"
}
});
````

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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a default but overridable

Object.keys(ssh_options).map(function (key) {
result += "-o " + key + '=' + ssh_options[key] + ' '
})
return result.trim();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please match the indentation to the rest of the file

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is inconsistent use of semicolons here, please use them everywhere

/*
* 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant given similar code in buildSshOptions, but also doesn't work because buildSshOptions expects ssh_options to be an object

ssh_options = options.ssh ? ssh_options.concat(options.ssh) : ssh_options;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make ssh_options camelCase please? nothing else in this project is snake_case

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);
});