【问题标题】:Implementing "TYPE A" in an FTP server在 FTP 服务器中实现“TYPE A”
【发布时间】:2014-05-10 10:29:45
【问题描述】:

我正在编写一个 FTP 服务器(在 Qt/C++ 中),现在我对“TYPE A”使用“200 Ok”,但我真的将其视为与“TYPE I”相同 - 文件发送为 -是。

我应该如何正确实现 TYPE A?以文本模式而不是二进制模式打开文件就足够了吗?

另外,我假设 SIZE 方法应该比在磁盘上返回文件的大小更复杂,它应该读取它并执行文本替换,然后以这种方式返回大小?

编辑:作为对评论的回应,以下是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.

【问题讨论】:

  • “我为“TYPE A”返回成功”到底是什么意思? “我应该如何正确实施 TYPE A”是什么意思?您的问题目前假设您的头脑中有太多的知识,而不是像我这样的其他人。 ;)
  • 这就是命令的命名方式。你在控制连接中写“TYPE A”来指定ASCII,“TYPE I”代表Image——意思是二进制。
  • @LaszloPapp:确定有:在 RFC959 第 27 页描述了 A(ASCII)、I(图像)和 E(EBCDIC)类型。
  • @sashoalm:该标准只有 ascii 类型,没有“a”类型,但请随意在标准中指出“type a”。
  • @LaszloPapp 他们列在“REPRESENTATION TYPE (TYPE)”中,但是是的,很难找到。但是如果你打开一个 FTP 客户端,他们通常会记录控制连接,你会在那里看到它。

标签: c++ qt ftp ftp-server


【解决方案1】:

要以 ASCII 模式(类型 A)传输文件,您需要以文本模式打开文件,然后以行结束 CRLF 传输它们。如果您执行 SIZE 命令,您将需要根据传输类型报告大小。因为这显然是为了获得正确的大小而扫描整个文件的开销太大,如果该命令未在图像模式下使用,服务器通常会返回550 SIZE not allowed in ASCII mode

【讨论】:

  • 谢谢。顺便说一句,我似乎太懒了,因为当我终于找到摘录时,它就在那里。我猜这个网站在这里起到了橡皮鸭的作用:)
猜你喜欢
  • 1970-01-01
  • 2021-01-04
  • 2014-02-26
  • 1970-01-01
  • 1970-01-01
  • 2017-03-17
  • 1970-01-01
  • 1970-01-01
  • 2011-02-09
相关资源
最近更新 更多