4. File SIZE
The FTP command, SIZE OF FILE (SIZE), is used to obtain the transfer
size of a file from the server-FTP process. This is the exact number
of octets (8 bit bytes) that would be transmitted over the data
connection should that file be transmitted. This value will change
depending on the current STRUcture, MODE, and TYPE of the data
connection or of a data connection that would be created were one
created now. Thus, the result of the SIZE command is dependent on
the currently established STRU, MODE, and TYPE parameters.
The SIZE command returns how many octets would be transferred if the
file were to be transferred using the current transfer structure,
mode, and type. This command is normally used in conjunction with
the RESTART (REST) command when STORing a file to a remote server in
STREAM mode, to determine the restart point. The server-PI might
need to read the partially transferred file, do any appropriate
conversion, and count the number of octets that would be generated
when sending the file in order to correctly respond to this command.
Estimates of the file transfer size MUST NOT be returned; only
precise information is acceptable.
4.1. Syntax
The syntax of the SIZE command is:
size = "Size" SP pathname CRLF
The server-PI will respond to the SIZE command with a 213 reply
giving the transfer size of the file whose pathname was supplied, or
an error response if the file does not exist, the size is
unavailable, or some other error has occurred. The value returned is
in a format suitable for use with the RESTART (REST) command for mode
STREAM, provided the transfer mode and type are not altered.
size-response = "213" SP 1*DIGIT CRLF /
error-response
Note that when the 213 response is issued, that is, when there is no
error, the format MUST be exactly as specified. Multi-line responses
are not permitted.
Where the command is correctly parsed but the size is not available,
perhaps because the pathname identifies no existing entity or because
the entity named cannot be transferred in the current MODE and TYPE
(or at all), then a 550 reply should be sent. Where the command
cannot be correctly parsed, a 500 or 501 reply should be sent, as
specified in [3]. The presence of the 550 error response to a SIZE
command MUST NOT be taken by the client as an indication that the
file cannot be transferred in the current MODE and TYPE. A server
may generate this error for other reasons -- for instance if the
processing overhead is considered too great. Various 4xy replies are
also possible in appropriate circumstances.
4.3. FEAT Response for SIZE
When replying to the FEAT command [6], a server-FTP process that
supports the SIZE command MUST include a line containing the single
word "SIZE". This word is case insensitive, and MAY be sent in any
mixture of upper or lower case, however it SHOULD be sent in upper
case. That is, the response SHOULD be:
C> FEAT
S> 211- <any descriptive text>
S> ...
S> SIZE
S> ...
S> 211 END
The ellipses indicate place holders where other features may be
included, and are not required. The one-space indentation of the
feature lines is mandatory [6].
4.4. Size Examples
Consider a text file "Example" stored on a Unix(TM) server where each
end of line is represented by a single octet. Assume the file
contains 112 lines, and 1830 octets total. Then the SIZE command
would produce:
C> TYPE I
S> 200 Type set to I.
C> size Example
S> 213 1830
C> TYPE A
S> 200 Type set to A.
C> Size Example
S> 213 1942
Notice that with TYPE=A the SIZE command reports an extra 112 octets.
Those are the extra octets that need to be inserted, one at the end
of each line, to provide correct end-of-line semantics for a transfer
using TYPE=A. Other systems might need to make other changes to the
transfer format of files when converting between TYPEs and MODEs.
The SIZE command takes all of that into account.
Since calculating the size of a file with this degree of precision
may take considerable effort on the part of the server-PI, user-PIs
should not used this command unless this precision is essential (such
as when about to restart an interrupted transfer). For other uses,
the "Size" fact of the MLST command (see section 7.5.7) ought be
requested.