Indy FTP TransferType

…衆ロ難τιáo~ 提交于 2019-12-07 22:21:24

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1389701/indy-ftp-transfertype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!