本文介绍了FTP二进制文件x ASCII自动选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写一个FTP插件(使用python的ftplib),我想知道如果应该使用二进制或ASCII传输方法来确定给定文件,最好的方法是什么。换句话说,自动传输模式。

我开始研究这个问题,因为我得到了关于双线和谷歌搜索的问题报告,结果发现二进制模式应该是负责任的[1] [2]。

它可能使用白名单或黑名单扩展名应该是二进制或ascii,但它可能不存在,当然这是一个问题哪种方法wl x bl,bxa)然后使用。它听起来不够稳固(不完美的列表,缺乏扩展名)。



- >问题:对于给定的文件,选择二进制还是ASCII传输模式? (如果有...)

谢谢

[1]

[2]

解决方案

首先,您需要检查文件的 BOM标记它确定UTF16或UTF8。如果它们存在,则该文件为99.9%的可能性为文本文件。

接下来,您可以扫描该文件并检查它是否包含代码小于32且不是9,10和13(TAB,LF,CR)的字符。如果文件中没有这样的字符,那么该文件可能是 文本。但这里没有保证,或者用户可以明确请求文件以二进制模式传输。

I program a FTP addon (using python's ftplib) and I wonder what would be the best way to determine, if it should use Binary or ASCII transfer method for a given file. In other words "automatic" transfer mode.

I started looking into this as I got issue report about double lines and googling turned out that binary mode should be responsible [1][2].

It might be using whitelisting or blacklisting extension supposed to be binary or ascii, but it might not be present and of course a question which of the methods (wl x bl,b x a) to use then. It does not sound solid way enough (imperfect list, lack of extension).

-> question: For a given file what's a solid way to choose either binary or ascii transfer mode? (if there is any...)
Thank you

[1] http://www.seo-creative.co.uk/tutorials/ftp-client-giving-you-double-line-breaks/
[2] http://www.chami.com/html-kit/support/docs/pages/h000114.html

解决方案

First of all, you need to inspect the file for BOM marks which identify UTF16 or UTF8. If they are present, than with 99,9% probability the file is a text file.

Next you can scan the file and check if it contains characters with codes less than 32 and not 9, 10 and 13 (TAB, LF, CR). If there are no such characters in the file, then the file is probably a text. But there's no guarantee here OR the user can explicitly request the file to be transferred in binary mode.

这篇关于FTP二进制文件x ASCII自动选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 11:40