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); };