سؤال

I'm trying to build a simple FTP server, but for the STOR command I'm not sure how to distinguish between the data connection closing because all the data was sent, or if the data connection closed prematurely.

In the RETR command, I know the size of the file I'm sending, but in the STOR command, I don't know how many bytes I should receive.

And if the data connection closes prematurely, what should the FTP server do?

هل كانت مفيدة؟

المحلول

The FTP server cannot know if the transfer was interrupted or not. That is a shortcoming of the protocol. The server only stores as many bytes it gets, and in case of network problems it is up to the client to resume the upload (normally by asking the server for the remote file size, and then do a stor combined with skipping the number of bytes that was already saved).

This behaviour often cause issues in setups where there is a server side process that want to take action on uploaded files, since it can never know when the upload is complete. This is normally handled by letting the client rename files after upload has completed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top