| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: ASCII Transfers</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: ASCII Transfers</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | Like most FTP servers (and clients), <code>proftpd</code> contains code |
| 15 | specifically for handling files that are transferred in ASCII mode. |
| 16 | <a href="http://www.faqs.org/rfcs/rfc959.html">RFC959</a> requires that when |
| 17 | sending a file transferred in ASCII mode, the server (or client) <b>must</b> |
| 18 | ensure that every carriage return (CR) character is followed by a line feed |
| 19 | (LF) character. The receiving program then checks the file for these CRLF |
| 20 | sequences and re-translates them into the native line-ending format for the |
| 21 | host machine. This allows clients on platforms whose ASCII line ending is |
| 22 | CRLF (<i>e.g.</i> Windows) to send those files to platforms whose ASCII line |
| 23 | ending is LF (<i>e.g.</i> Unix), at the cost of complex handling of ASCII |
| 24 | data in FTP. |
| 25 | |
| 26 | <p> |
| 27 | The FTP <code>TYPE</code> command is used by the client to tell the server |
| 28 | which transfer type is to be used: <code>A</code> for ASCII, <code>I</code> |
| 29 | for binary. For the <code>LIST</code> and <code>NLST</code> FTP commands, |
| 30 | the data transfer is <i>always</i> done in ASCII mode. The other FTP |
| 31 | commands are unaffected by the transfer mode, with two notable exceptions: |
| 32 | <code>REST</code> and <code>SIZE</code>. |
| 33 | |
| 34 | <p> |
| 35 | Why should <code>REST</code> (for resuming a transfer) and <code>SIZE</code> |
| 36 | (for determining the size of a file on the server) be affected? The |
| 37 | <code>REST</code> command tells the server at which byte to begin transferring |
| 38 | a file. Recall that since the server may have altered the bytes received |
| 39 | from the client in ASCII mode, the offset used by the client may be in |
| 40 | a different position of the file on the server. Similarly, in ASCII mode, |
| 41 | the size of the file that the client will receive may be different than |
| 42 | the actual size of the file on the server. For example, a Unix FTP server |
| 43 | transferring a file in ASCII mode to a Windows FTP client will need to add |
| 44 | CR characters, increasing the size of the file (from the server's point of |
| 45 | view). |
| 46 | |
| 47 | <p> |
| 48 | Properly handling the <code>SIZE</code> command would require the server to |
| 49 | scan the file in question and perform the translation logic, which is |
| 50 | resource-intensive. It is an easy way for a malicious client to try a |
| 51 | "denial of service" attack on the server, forcing the server to |
| 52 | perform many time-consuming calculations needlessly. The <code>REST</code> |
| 53 | command can be abused in the same fashion. ProFTPD thus <b>does not</b> |
| 54 | perform ASCII translation when handling the <code>REST</code> and |
| 55 | <code>SIZE</code> commands. |
| 56 | |
| 57 | <p> |
| 58 | An FTP client will usually use <code>SIZE</code> when it wants to resume |
| 59 | downloading file. However, clients in general should not be resuming downloads |
| 60 | in ASCII mode. Resuming downloads in binary mode is the recommended way. |
| 61 | |
| 62 | <p><a name="FAQ"> |
| 63 | <b>Frequently Asked Questions</b> |
| 64 | |
| 65 | <p> |
| 66 | <font color=red>Question</font>: The <code>SIZE</code> <i>used</i> to work, |
| 67 | regardless of the ASCII/binary mode, in 1.2.10. Why was it changed?<br> |
| 68 | <font color=blue>Answer</font>: The restriction on the <code>SIZE</code> |
| 69 | command first appeared in 1.3.0rc1. |
| 70 | |
| 71 | <p> |
| 72 | Prior to the restriction, the file size reported by <code>proftpd</code> |
| 73 | via <code>SIZE</code> did not take into account any possible CRLF translation |
| 74 | (as mandated by RFC959 for ASCII mode transfers); this means that the |
| 75 | reported size could be misleading. The reported size might not match the |
| 76 | actual number of bytes that a client might download. Now, <code>proftpd</code> |
| 77 | would rather provide no answer at all to a <code>SIZE</code> over providing |
| 78 | a wrong answer. |
| 79 | |
| 80 | <p> |
| 81 | <hr> |
| 82 | <font size=2><b><i> |
| 83 | © Copyright 2017 The ProFTPD Project<br> |
| 84 | All Rights Reserved<br> |
| 85 | </i></b></font> |
| 86 | <hr> |
| 87 | |
| 88 | </body> |
| 89 | </html> |