RETR and STOR Commands
RETR
RETR file-spec
Requests that the remote system send the specified file.
Receiving a '-' from the server should abort the RETR command and the server will wait for another command.
The reply from the remote system is:
<number-of-bytes-that-will-be-sent> (as ascii digits)
-File doesn't exist
You then reply to the remote system with:
SEND (ok, waiting for file)
The file is then sent as a stream of exactly the number of 8-bit bytes specified. When all bytes are received control passes back to you (the remote system is waiting for the next command). If you don't receive a byte within a reasonable amount of time you should abort the file transfer by closing the connection.
STOP (You don't have enough space to store file)
Replies could be:
+ok, RETR aborted
You are then ready to send another command to the remote host.
STOR
STOR { NEW | OLD | APP } file-spec
Tells the remote system to receive the following file and save it under that name.
Receiving a '-' should abort the STOR command sequence and the server should wait for the next command.
NEW specifies it should create a new generation of the file and not delete the existing one.
Replies could be:
+File exists, will create new generation of file
+File does not exist, will create new file
-File exists, but system doesn't support generations
OLD specifies it should write over the existing file, if any, or else create a new file with the specified name.
Replies could be:
+Will write over old file
+Will create new file
(OLD should always return a '+')
APP specifies that what you send should be appended to the file on the remote site. If the file doesn't exist it will be created.
Replies could be:
+Will append to file
+Will create file
(APP should always return a '+')
You then send:
SIZE <number-of-bytes-in-file> (as ASCII digits)
where number-of-bytes-in-file is the exact number of 8-bit bytes you will be sending.
The remote system replies:
+ok, waiting for file
You then send the file as exactly the number of bytes specified above.
When you are done the remote system should reply:
+Saved <file-spec>
-Couldn't save because (reason)
-Not enough room, don't send it
This aborts the STOR sequence, the server is waiting for your next command.
You are then ready to send another command to the remote host.