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/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); 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",