Skip to content
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
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ scp.send({
});
````

You can also pass, `ssh options`, the ones which should be passed to scp through `-o` command line option

The code

````javascript
scp.send({
file : './file.txt',
user : 'username',
host : 'myServer',
port : 22,
path : '~',
ssh_options : {
ControlMaster : 'no',
StrictHostKeyChecking : 'yes'
}
````

is equivalent to following command line

````
scp -o ControlMaster=no -o StrictHostKeyChecking=yes -P 22 username@myServer:~/file.txt ~
````


###scp.get(options, cb)

Transfer a file from a remote host (in your `~/.ssh/config`) to the current computer.
Expand All @@ -65,6 +89,28 @@ scp.get({
});
````

You can also pass, `ssh options`, the ones which should be passed to scp through `-o` command line option.

The code

````javascript
scp.get({
file : '~/file.txt',
user : 'username',
host : 'myServer',
port : 22,
path : '~',
ssh_options : {
ControlMaster : 'no',
StrictHostKeyChecking : 'yes'
}
````
is equivalent to following command line

````
scp -o ControlMaster=no -o StrictHostKeyChecking=yes -P 22 username@myServer:~/file.txt ~
````

## license

(The MIT License)
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]>",
"Manish Gupta <[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
53 changes: 36 additions & 17 deletions scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ var scp = module.exports = {};
* Transfer a file to a remote host
*/
scp.send = function (options, cb) {
var command = [
'scp',
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
var command = ['scp'];

if (options.ssh_options) {
Object.keys(options.ssh_options).forEach(
function(opt_name) {
command.push("-o " + opt_name + "=" + options.ssh_options[opt_name]);
}
);
}

if ( !options.hasOwnProperty('recursive') || options.recursive )
command.push("-r");

command.push(
'-P', (options.port ? options.port : '22'),
options.file,
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.path,
];
(options.user ? options.user + '@' : '') + options.host + ":" + options.path);

exec(command.join(' '), function (err, stdout, stderr) {
if (cb) {
cb(err, stdout, stderr);
Expand All @@ -32,15 +41,25 @@ scp.send = function (options, cb) {
* Grab a file from a remote host
*/
scp.get = function (options, cb) {
var command = [
'scp',
'-r',
'-P',
(options.port == undefined ? '22' : options.port),
'-o "ControlMaster no"', //callback is not fired if ssh sessions are shared
(options.user == undefined ? '' : options.user+'@') + options.host + ':' + options.file,
options.path
];

var command = ['scp'];

if (options.ssh_options) {
Object.keys(options.ssh_options).forEach(
function(opt_name) {
command.push("-o " + opt_name + "=" + options.ssh_options[opt_name]);
}
);
}

if ( !options.hasOwnProperty('recursive') || options.recursive )
command.push("-r");

command.push(
'-P', (options.port ? options.port : '22'),
(options.user ? options.user + '@' : '') + options.host + ":" + options.file,
options.path);

exec(command.join(' '), function (err, stdout, stderr) {
if (cb) {
cb(err, stdout, stderr);
Expand Down
20 changes: 20 additions & 0 deletions test/get-with-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var scp = require('../');

scp.get(
{
file : '~/what',
host : 'uspro603.server4you.net',
user : 'alpha',
recursive : false,
path : '.',
ssh_options :
{
ControlMaster : 'no',
StrictHostKeyChecking : 'no'
}
},
function ()
{
console.log(arguments);
}
);
21 changes: 21 additions & 0 deletions test/send-with-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var scp = require('../');

scp.send(
{
file : './what',
host : 'uspro603.server4you.net',
user : 'alpha',
// host : 'core',
recursive : false,
path : '~',
ssh_options :
{
ControlMaster : 'no',
StrictHostKeyChecking : 'no'
}
},
function ()
{
console.log(arguments);
}
);