开发者

What content cannot be FTP'd safely in binary mode?

开发者 https://www.devze.com 2023-02-02 06:44 出处:网络
FTP predominately provides two transfer modes: ASCII and BINARY. ASCII mode is generally intended for text-based content and that BINARY mode is generally intended for transferring content as-is, alt

FTP predominately provides two transfer modes: ASCII and BINARY.

ASCII mode is generally intended for text-based content and that BINARY mode is generally intended for transferring content as-is, although transferring text-based content in BINARY mode is often perfectly safe.

ASCII mode is required for transferred CGI scripts to execute correctly - a CGI script transferred in BINARY mode will often re开发者_运维问答sult in an HTTP 500 upon execution.

Are there any other types of content that are known to require transfer by ASCII mode? What content will 'break' when transferred in BINARY mode that would not 'break' when transferred in ASCII mode?


Binary mode will work for any data.

The problem with CGI scripts is that they are often edited on Windows with CRLF line endings, and the servers expect the line endings to be just LF. ASCII mode solves this. But modern servers don't care about this anymore, and also you can convert line endings on the server side if you have right tools, and also you can tell the editor on the client side to use LF as a line ending if you need to (at least Notepad++ seems to do this).

I never saw charset conversion taking place in ASCII mode, just because ASCII is a charset.

Update: ASCII mode can be used to convert data between EBCDIC and ASCII when connecting to mainframes. In this case binary mode would require manual conversion after transfer.


I believe ASCII mode was created to transfer less data through modem connection (it uses 7 bits to transfer data). So BINARY mode can be used for anything even for text, or any other content that can be transferred in ASCII mode, but it uses slightly more bandwidth :)

Also with the introduction of UTF you are not really safe to transfer text anymore with ASCII; so really - the modern ftp clients use only BINARY mode ...

EDIT: My answer is not correct about the 7bits transfer mode. This is what wikipedia says about ascii vs binary: "ASCII mode: used for text. Data is converted, if needed, from the sending host's character representation to "8-bit ASCII" before transmission, and (again, if necessary) to the receiving host's character representation. As a consequence, this mode is inappropriate for files that contain data other than plain text.

Image mode (commonly called Binary mode): the sending machine sends each file byte for byte, and the recipient stores the bytestream as it receives it. Image mode support has been recommended for all implementations of FTP."

Note the last sentence which says that actually binary mode is recommended for all transfers ...

SO bottomline use BINARY for all transfers, and you will be okay.

Hope this helps, Moszi

0

精彩评论

暂无评论...
验证码 换一张
取 消