File Structure, Transfer Modes, and Error Recovery
III.C File Structure and Transfer Modes
The only file structures supported directly in FTP at the present time are record structures. However, the use of record structures is not mandatory. A user with no record structure in his file should be able to store and retrieve his file at any HOST. A user wishing to transmit a record structured file must send the appropriate FTP 'STRU' command (the default assumption is no record structure). A serving HOST need not accept record structures, but it must inform the user of this fact by sending an appropriate reply. Any record structure information in the data stream may subsequently be discarded by the receiver.
All data transfer must end with an EOF. The EOF is defined by the data transfer mode. For files that have record structures, an EOR is also defined by the transfer mode. Only the transfer modes and representation type combinations that have EOR defined may be used for transfer or files with record structures. Records may be of zero length but they must be contained in file boundaries. The relationship between files and records is heirarchical and an EOF implies an EOR.
The following data transfer modes are defined in FTP:
1. Stream: The file is transmitted as a stream of bytes of the specified byte size. The EOF is signalled by closing the data connection. Any representation type and byte size may be used in the stream mode but record structures are possible only with the ASCII representation type. The convention is that the ASCII character CR (Carriage Return, Code 13.) followed by LF (Line Feed, Code 10.) Indicates an EOR in stream mode and ASCII representation type. This is the default mode, and it is recommended that this mode be implemented by all.
2. Text: The file is ASCII text transmitted as sequence of 8-bit bytes in the ASCII representation type. Record structures are allowed in this mode. The EOR and EOF are defined by the presence of special "TELNET-control" codes (most significant bit set of one) in the data stream. The EOR code is 192 (octal 300, hex C0). The EOF code os 193 (octal 301, hex C1). The byte size for transfer is 8 bits.
3. Block: The file is transmitted as a series of data blocks preceded by one or more header bytes. The header bytes contain a count field and descriptor code. The count field indicates the total length of the data block in bytes, thus marking the beginning of the next data block (there are no filler bits). The descriptor code defines last file block (EOF), last record block (EOR), restart marker (see section III.D), or suspect data (i.e. the data being transferred is suspected of errors and is not reliable). Record structures are allowed in this mode, and any representation type or byte size may be used. The header consists of integral number of bytes whose length is greater than or equal to 24 bits. Only the least significant 24 bits (right-jusified) of header shall have information, other must significant bits must be zero. Of the 24 bits of header information, the 16 low order bits shall represent byte count, and the 8 high order bits shall represent descriptor codes as shown below.
Integral data bytes > 24
| Must be Zero | Descriptor | Byte Count |
| 0 to 231 bits | 8 bits | 16 bits |
The following descriptor codes are assigned:
Code Meaning
0 An ordinary block of data.
1 End of data block is EOR.
2 End of data block is EOF.
3 Suspected errors in data block.
4 Data block is a restart marker.
The restart marker is imbedded in the data stream as integral number of 8-bit bytes (representing printable ASCII characters) right-justified in integral number of data bytes greater than 8 bits. For example if the byte size is 7 bits, the restart marker byte would be one byte right-justified per two 7-bit bytes as shown below:
Two 7-bit bytes
| | Marker Char|
| | 8 bits |
For byte size of 16 bits or more, two more marker bytes shall be packed right-justified. The end of the marker may be delimited by the character SP (code 32.). If marker characters do no exactly fit an integral byte, the unused character slots should contain the ASCII character SP (code 32.). For example, to transmit a six character marker in a 36-bit byte size, the following three 36.bit bytes would be sent:
| Zero | Descriptor | |
| 12 bits | code=4 | Byte count=2 |
| | Marker | Marker | Marker | Marker |
| | 8 bits | 8 bits | 8 bits | 8 bits |
| | Marker | Marker | SP | SP |
| | 8 bits | 8 bits | 8 bits | 8 bits |
4. Hasp: The file is transmitted as a sequence of 8-bit bytes in the standard Hasp-compressed data format (document to be issued by Bob Braden, UCLA). This mode achieves considerable compression of data for print files. Record structures are allowed in the Hasp mode.
III.D Error Recovery and Restart
There is no provision for detecting bits lost or scrambled in data transfer. This issue is perhaps handled best at the NCP level where it benefits most users. However, a restart procedure is provided to protect user from system failures (such as failure of either HOST, FTP-process, or the IMP subnet).
The restart procedure is defined only for the block mode of data transfer. It requires the sender of data to insert a special marker code in teh data stream with some marker information. The marker information has meaning only to the sender, but must consist of printable ASCII characters. The printable ASCII characters are defined to be codes 33. through 126. (i.e., not including codes 0. through 31. and the characters SP and DEL). The marker could represent a bit-count,a record-count, or any other information by wich a system may identify a data checkpoint. The receiver of data, if it implements the restart procedure, would then mark the corresponding position of this marker in the receiving system, and return this information to the user.
In the event of a system failure, the user can restart the data transfer by identifying the marker point with the FTP restart procedure. The following examples Illustrate the use of the restart procedure.
-
When server is the sender of data, the server-FTP process inserts an appropriate marker block in the data stream at a convenient data point. The user-FTP process receiving the data, marks the coressponding data point in its file system and conveys the last known sender and receiver marker information to the user. In the event of system failure, the user or user-FTP process restarts the server at the last server marker by sending a restart command with the server's marker code at its argument. The restart command is transmitted over the TELNET connection and is immediately followed by the command (such as store or retrieve) which was being executed when the system failure occured.
-
When user is the sender of data, the user-FTP process inserts the appropriate marker block in the data stream. The server-FTP process receiving the data, marks the corresponding data point in its file system. The server does not store this marker but conveys the last known sender and receiver marker information to the user over the TELNET connections by appropriate reply codes. The user or the user-FTP process then restarts transfer in a manner identical to that described in the first example.