From 95bbce8d7c3585febb0d0107557896c05b305c54 Mon Sep 17 00:00:00 2001 From: Erin Kosewic Date: Tue, 28 Aug 2018 15:31:44 -0700 Subject: [PATCH 1/2] if no custom client passed set client to global_client to keep defaults --- lib/scp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scp.js b/lib/scp.js index 85e2675..6a6d68e 100644 --- a/lib/scp.js +++ b/lib/scp.js @@ -94,7 +94,7 @@ exports.Client = Client; exports.scp = function(src, dest, client, callback) { if (typeof client === 'function') { callback = client; - client = new Client(); + client = global_client; } client.on('error', callback); var parsed = client.parse(src); From ae415e5918f28c530ba31f19206c0b82481540ee Mon Sep 17 00:00:00 2001 From: Erin Kosewic Date: Tue, 28 Aug 2018 17:25:35 -0700 Subject: [PATCH 2/2] revert back to sftp open for _write --- lib/client.js | 39 ++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/client.js b/lib/client.js index f73981d..6232892 100644 --- a/lib/client.js +++ b/lib/client.js @@ -227,28 +227,25 @@ Client.prototype.write = function(options, callback) { } }; - var step = _.throttle(function(total_transferred, chunk, total) { - self.emit( - "transfer", - undefined, - // percentage up to 99 - // since it's incremented in the logger - Math.min(Math.floor(total_transferred / total * 100), 99), - 100 - ), - 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.open(destination, 'w', attrs, function(err, handle) { + _write(handle); + }); + } else { + _write(handle); } - ); + }); + + }); }; diff --git a/package.json b/package.json index 939a070..bf49e67 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "async": "~0.9.0", "glob": "~7.0.3", "lodash": "~4.11.1", - "ssh2": "^0.6.0" + "ssh2": "^0.5.4" }, "repository": { "type": "git",