1

I'm writing an FTP server (in Qt/C++), and right now I with "200 Ok" to "TYPE A", but I really treat it the same as "TYPE I" - files are sent as-is.

How should I go about properly implementing TYPE A? Would opening the files in text mode instead of binary mode be enough?

Also, I assume that the SIZE method should be more complex than returning the file's size on disk, it should read it and perform the text substitutions, and return the size that way?

Edit: In response to a comment, here's the relevant excerpt from the RFC959 spec:

     3.1.1.1.  ASCII TYPE

        This is the default type and must be accepted by all FTP
        implementations.  It is intended primarily for the transfer
        of text files, except when both hosts would find the EBCDIC
        type more convenient.

        The sender converts the data from an internal character
        representation to the standard 8-bit NVT-ASCII
        representation (see the Telnet specification).  The receiver
        will convert the data from the standard form to his own
        internal form.

        In accordance with the NVT standard, the <CRLF> sequence
        should be used where necessary to denote the end of a line
        of text.  (See the discussion of file structure at the end
        of the Section on Data Representation and Storage.)

        Using the standard NVT-ASCII representation means that data
        must be interpreted as 8-bit bytes.

        The Format parameter for ASCII and EBCDIC types is discussed
        below.
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • What exactly do you mean by 'I return success for "TYPE A"'? What do you mean by "How should I go about properly implementing TYPE A"? Your question currently assumes too much knowledge that is in your head, but not in others' like mine. ;) – László Papp May 10 '14 at 10:38
  • That's how the commands are named. You write "TYPE A" in the control connection to specify ASCII, and "TYPE I" stands for Image - meaning binary. – sashoalm May 10 '14 at 10:47
  • @LaszloPapp: sure there is: At RFC959 page 27 are the types A (ASCII), I (Image) and E (EBCDIC) described. – Steffen Ullrich May 10 '14 at 10:48
  • @sashoalm: the standard only has ascii type, not "a" type, but feel free to point "type a" out in the standard. – László Papp May 10 '14 at 10:51
  • @LaszloPapp They're listed in "REPRESENTATION TYPE (TYPE)", but yes, it's not easy to find. But if you open an FTP client, they usually log the control connection, you'll see it there. – sashoalm May 10 '14 at 11:00
  • And that is what I meant by knowledge assumption. I would argue if it was crystal clear. ;) – László Papp May 10 '14 at 11:00

1 Answers1

3

For transferring files with ASCII mode (type A) you would need to open the files in text mode and then transfer them with line ending CRLF. If you implement the SIZE command you would be required to report the size according to the transfer type. Because this is obviously too much overhead to scan the whole file just for getting the size right server often return 550 SIZE not allowed in ASCII mode if the command is used not in image mode.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • Thanks. Btw, I was too lazy, it seems, because when I finally when around to finding the excerpt, it was all there. I guess the site helped as a rubber duck here :) – sashoalm May 10 '14 at 10:51