Skip to content
Closed
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
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -18,18 +18,22 @@ 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);
else console.log('File transferred.');
});
````

##methods
## methods

###scp.send(options, cb)
### scp.send(options, cb)

Send a file to a remote host (in your `~/.ssh/config`)

Expand All @@ -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.

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)
sshOptions: {
StrictHostKeyChecking: "no"
}
});
````

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"Gabriel Preston <[email protected]>",
"Joseph Silvestre <[email protected]>",
"appr <[email protected]>",
"Daniel Phatthanan <[email protected]>"
"Daniel Phatthanan <[email protected]>",
"Julien Stébenne <[email protected]>"
],
"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,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
*/
Expand All @@ -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,
];
Expand All @@ -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
];
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',
sshOptions: {
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: '~',
sshOptions: {
StrictHostKeyChecking: 'no',
UserKnownHostsFile: '/dev/null'
}
}, function () {
console.log(arguments);
});