Indy FTP 传输类型

发布于 2024-08-04 12:05:40 字数 314 浏览 10 评论 0原文

我正在使用 IdFTP (Indy 10) 组件从远程位置下载一些文件(zip 和 txt)。在获取每个文件之前,我将 TransferType 设置为二进制。

IdFTP.TransferType := ftBinary;
IdFTP.Get(ASource, ADest, AOverwrite);

我希望可以使用二进制模式下载文本和二进制文件。然而,看起来文本文件内容混乱,而 zip 文件下载正确。如果我将文本文件的 TransferType 设置为 ASCII,它会按预期工作。如何检测为给定文件设置哪种传输类型?有共同点或自动设置吗?

I'm using the IdFTP (Indy 10) component to download some files (zip and txt) from a remote location. Before getting each file I set the TransferType to binary.

IdFTP.TransferType := ftBinary;
IdFTP.Get(ASource, ADest, AOverwrite);

I expect that both text and binary files can be downloaded using the binary mode. However it looks like text files contents is messed up while zip files are downloaded correctly. If I set the TransferType to ASCII for text files it works as expected. How can I detect which TransferType to set for a given file? Is there a common denominator or auto setting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦幻的心爱 2024-08-11 12:05:40

我不明白二进制标志如何弄乱传输的文件。二进制类型意味着服务器按原样传输文件而不进行任何处理。

FTP 服务器应该使用 ASCII 标志的唯一目的是正确处理文本文件中的行尾,通常 (1) Unix 中仅换行或 (2) Windows 中回车 + 换行。但现在大多数文本编辑器都可以在任一系统中处理这两种情况。

因此,最安全的方法是仅对众所周知的文本文件(可能仅具有 .txt 扩展名的文件)使用 ASCII 标志,并对所有其他文件使用二进制标志。

I don't see how the Binary flag can mess up transferred files. Binary type means the server transfers the files without any processing, as is.

The only thing that an FTP server should use the ASCII flag for, is to correctly handle the end of line in text files, usually (1) either only Line Feed in Unix or (2)Carriage Return + Line Feed in Windows. But nowadays most text editors handle both in either system.

So the safest is use only ASCII flag for very well known text files, probably only files with a .txt extension, and use Binary flag for all the others.

一向肩并 2024-08-11 12:05:40

如果有疑问,请排除它(!) - 尝试使用 Windows 命令行 FTP 程序从服务器传输文件,并查看文本文件是否仍然出现错误。该程序将传输二进制(命令 BIN)或文本(命令 ASCII)。如果您用此方法传输文件,但它们的到达方式仍然与您的预期不同,则说明服务器端正在执行某些操作*。如果他们顺利到达,那么你(或印地)正在做某事。 :-)

*文本文件在什么情况下被搞乱了?如果您要传输 unicode 文本文件,则最好将它们传输为 BINary。我必须承认,正如 @unknown (yahoo) 所说,在大多数情况下你应该坚持使用 BIN 模式。

When in doubt, rule it out (!) - try transferring the files from the server using the Windows commandline FTP program, and see if text files still come out wrong. The program will transfer binary (command BIN) or text (command ASCII). If you transfer files with this and they still arrive differently to your expectation, then something is being done at the server end*. If they arrive fine, then either you (or Indy) are doing something. :-)

*In what way are the text files messed up? If you're transferring unicode text files, you might be better off transferring them as BINary anyway. I must admit that, as @unknown (yahoo) said, in most cases you should probably stick to BIN mode.

蓝颜夕 2024-08-11 12:05:40

我想这还取决于您查看文本文件的方式,ANSI 还是 WideChar,文本是否混乱。

I guess it would also depend on how you are viewing the text file, ANSI or WideChar as to whether the text is messed up or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文