diff --git a/lib/jsftp.js b/lib/jsftp.js index d48c2de..5a1c12e 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -563,7 +563,35 @@ Ftp.prototype.put = function(from, to, callback) { if (from instanceof Buffer) { this.getPutSocket(to, function(err, socket) { if (!err) { - socket.end(from); + var pointer = 0; + var SLICE = 1024*1024; + var done = false; + + socket.write(from.slice(0,SLICE)); + pointer = SLICE; + socket.on("drain", () => { + + if(from.length > pointer+SLICE) { + var newBuf = from.slice(pointer, pointer+SLICE); + pointer += SLICE; + } + else { + var newBuf = from.slice(pointer); + done = true; + } + socket.write(newBuf); + + self.emit("progress", { + filename: "BUFFER", + action: "put", + transferred: pointer, + total: from.length + }); + + if(done) { + socket.end(); + } + }) } }, callback); } else if (typeof from === 'string') {