Search code examples
ftpftp-server

When should 226 be sent from the FTP server?


I'm creating an FTP server in Qt, and I'm not sure when to send the 226 success response code for a RETR command.

Do I send it after all the data is written, but before the data connection socket is closed:

    reply(226);
    dataSocket()->disconnectFromHost();

or do I send it after the data connection socket is closed:

    dataSocket()->disconnectFromHost();
    dataSocket()->waitForDisconnected();
    reply(226);

Solution

  • http://www.ietf.org/rfc/rfc959.txt

    To prevent a race condition here, the server sends a reply (226) after closing the data connection.