You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to run code similar to the code example in the README:
ftp.get("remote/file.txt", "local/file.txt", err => {
if (hadErr) {
return console.error("There was an error retrieving the file.");
}
const stats = fs.statSync("local/file.txt");
console.log(stats.size);
console.log("File copied successfully!");
});
I found that the file size is not always the full file at this point, when the callback is called. Only after a short wait, the full file is on the disk.
Looking at Ftp.get code, it looks like the problem might be that the callback is being called on socket.end and socket.close and actually should only be called once the "finish" event of the fileWriteStream is emitted.
const writeStream = fs.createWriteStream(localPath);
writeStream.on("error", callback);
writeStream.on("finish", callback); // should this be added ???
socket.on("readable", () => {
this.emitProgress({
filename: remotePath,
action: "get",
socket: socket
});
});
// This ensures that any expected outcome is handled. There is no
// danger of the callback being executed several times, because it is
// wrapped in `once`.
socket.on("error", callback);
socket.on("end", callback); // should this call the callback ???
socket.on("close", callback); // should this call the callback ???
The text was updated successfully, but these errors were encountered:
I was trying to run code similar to the code example in the README:
I found that the file size is not always the full file at this point, when the callback is called. Only after a short wait, the full file is on the disk.
Looking at Ftp.get code, it looks like the problem might be that the callback is being called on socket.end and socket.close and actually should only be called once the "finish" event of the fileWriteStream is emitted.
The text was updated successfully, but these errors were encountered: