From 32497e06992eeb7737f70ae6e1a16f872b6da4db Mon Sep 17 00:00:00 2001 From: Christian Ortiz Date: Sun, 5 Apr 2015 18:17:02 +0200 Subject: [PATCH 1/2] better error handling when opening sftp handle, better error message when something goes wrong. fixed path problems when file was not accessable on destination (path.join) --- lib/client.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index fb5902a..c379520 100644 --- a/lib/client.js +++ b/lib/client.js @@ -223,15 +223,22 @@ Client.prototype.write = function(options, callback) { sftp.open(destination, 'w', attrs, function(err, handle) { if (err) { - // destination is directory + // destination could be a directory + // it eventually can't be accessible + // to prevent getting a destination like: + // /pubic/app.js/app.js + // we use path.dirname when joining destination = path.join( - destination, path.basename(options.source) + path.dirname(destination), path.basename(options.source) ); destination = unixy(destination); // for emit write event options.destination = destination; sftp.open(destination, 'w', attrs, function(err, handle) { + if (err) + throw new Error('There was an error opening the destination: ' + destination + + '\n' + err + '\n please check the destination file or folder for accessibility'); _write(handle); }); } else { From 2aa14a3868ddaf3c64128695024a106a32953271 Mon Sep 17 00:00:00 2001 From: Christian Ortiz Date: Wed, 3 Jun 2015 22:05:02 +0200 Subject: [PATCH 2/2] fixed typo --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index c379520..0ce5d36 100644 --- a/lib/client.js +++ b/lib/client.js @@ -226,7 +226,7 @@ Client.prototype.write = function(options, callback) { // destination could be a directory // it eventually can't be accessible // to prevent getting a destination like: - // /pubic/app.js/app.js + // /public/app.js/app.js // we use path.dirname when joining destination = path.join( path.dirname(destination), path.basename(options.source)