Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

@aballard/refactor #124

Open
wants to merge 7 commits 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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Thumbs.db
*.swo
*.log
node_modules/
lib-cov/
.buildpath
.settings
.yml
_site
test/run.js
.nyc_output
/coverage
27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

45 changes: 30 additions & 15 deletions bin/scp2
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

var fs = require('fs');
var path = require('path');
var client = require('../');
var prompt = require('prompt');
var client = require('../lib/scp');

main(process.argv.slice());

prompt.start();

function main(argv) {
var identify, src, dest;

Expand Down Expand Up @@ -76,10 +79,20 @@ function main(argv) {

client.on('error', function(err) {
if (err.code === 'ECONNREFUSED') {
prompt(' password: ', function(val) {
prompt.get({
properties: {
password: {
hidden: true
}
}
}, function (err, values) {
if (err) {
console.log('Password is required');
process.exit();
}
client.close();
delete client.__ssh;
defaults.password = val;
defaults.password = values.password;
scp(src, dest, defaults);
});
} else {
Expand All @@ -92,8 +105,18 @@ function main(argv) {
defaults.privateKey = fs.readFileSync(identify);
scp(src, dest, defaults);
} else if (!password) {
prompt(' password: ', function(val) {
defaults.password = val;
prompt.get({
properties: {
password: {
hidden: true
}
}
}, function(err, values) {
if(err) {
console.log('Password is required');
process.exit();
}
defaults.password = values.password;
scp(src, dest, defaults);
});
} else {
Expand Down Expand Up @@ -127,9 +150,9 @@ function helpMessage() {
function versionMessage() {
var pkg = require('../package.json');
var format = require('util').format;
console.log()
console.log();
console.log(format(' %s %s (%s)', pkg.name, pkg.version, process.platform));
console.log()
console.log();
process.exit();
}

Expand Down Expand Up @@ -163,14 +186,6 @@ function printLog(quiet) {
}
}

function prompt(str, fn) {
process.stdout.write(str);
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(val) {
fn(val.trim());
}).resume();
}

function scp(src, dest, defaults) {
console.log();
client.defaults(defaults);
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

31 changes: 21 additions & 10 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,28 @@ Client.prototype.write = function(options, callback) {
),
100;
});
sftp.fastPut(
options.source,
path.basename(options.source),
{
step
},
function(err) {
step.cancel();
callback(err);
sftp.open(destination, 'w', attrs, function (err, handle) {
if (err) {
// destination is directory
destination = path.join(
destination, path.basename(options.source)
);
destination = unixy(destination);
// for emit write event
options.destination = destination;
}
);
sftp.fastPut(
options.source,
destination,
{
step: step
},
function (err) {
step.cancel();
callback(err);
}
);
});
});
};

Expand Down
Loading