From 785cf63a5918b9d78f273b30b925d6d5377903ed Mon Sep 17 00:00:00 2001 From: mhuffnagle Date: Tue, 23 Oct 2018 11:11:11 -0400 Subject: [PATCH] Invoke Ftp.get callback when writeStream is finished --- lib/jsftp.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jsftp.js b/lib/jsftp.js index ebd8e8f..24eea9a 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -451,6 +451,7 @@ Ftp.prototype.get = function(remotePath, localPath, callback = NOOP) { const writeStream = fs.createWriteStream(localPath); writeStream.on("error", callback); + writeStream.on("finish", callback); socket.on("readable", () => { this.emitProgress({ @@ -464,8 +465,6 @@ Ftp.prototype.get = function(remotePath, localPath, callback = NOOP) { // danger of the callback being executed several times, because it is // wrapped in `once`. socket.on("error", callback); - socket.on("end", callback); - socket.on("close", callback); socket.pipe(writeStream); };