Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to emit end and close immediately at EOF during download #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,33 @@ FTP.prototype.get = function(path, zcomp, cb) {
};

function ondone() {
if (done && lastreply) {
self._send('MODE S', function() {
if (done) {
if (zcomp) {
// Switch back to mode stream only when compression mode
self._send('MODE S', function() {
source._emit('end');
source._emit('close');
}, true);
} else {
// Some clients do not close the data connection until they receive the 226 response from the server.
// This behavior is permitted by RFC 959. (The intent, now obsolete, was for clients to retrieve multiple
// files through one data connection, with a self-delimiting encoding of each file. The server could use
// 226 to say that it was closing the connection, or 250 to say that it wasn't. The most obvious client
// implementation wouldn't close the connection until it received 226.) However, I recommend that clients
// close the data connection immediately after seeing the end of data. One server, wu-ftpd 2.6.0, waits
// until the client closes the connection before it sends its 226 response; this screws up file transfers
// to clients that do not close the data connection immediately. This also wastes a round-trip time for other
// clients. (As of 1999, various versions of wu-ftpd run about half of the Internet's FTP servers. Many
// servers made an emergency switch to version 2.6.0 in October 1999 when major security holes were
// discovered in previous versions.)
//
// Referred from https://cr.yp.to/ftp/retr.html
//
// End/Close emmediately, not waiting for 226 or 250 any more.
source.resume();
source._emit('end');
source._emit('close');
}, true);
}
}
}

Expand Down