diff --git a/lib/client.js b/lib/client.js index 6f96850..bf618f1 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: + // /public/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 {