Query on FTP file formats

Discussion about BCA's Internet Hosting Service
David Cooke
Site Admin
Posts: 300
Joined: Thu 29 Dec 2005 23:22
Location: Axbridge, Somerset, UK

Query on FTP file formats

Post by David Cooke » Fri 11 Jan 2013 13:53

David Gibson wrote:On the off-chance one of you knows the answer to this... Do you know if, when files are FTPed to/from the web site, they undergo a format conversion, e.g. from CRLF to CR line endings?

Ive noticed something odd (well, odd to me). On the BCRA web server, the size of index.html is reported as 23932 bytes but Windows reports it as 24411, a difference of 479 bytes, which is the number of lines in the file.

Is there a format conversion going on, or do the systems count differently? Both seem odd - I mean, how does the server "know" to re-convert the file when I download it. (That is, it goes from 24411 to 23932 when I upload and, if I download that file, it becomes 24411 again.
Dave Cooke
BCA IT Working Party, BCA Web Services, National Cave Registry Co-ordinator, CSCC Webmaster

David Cooke
Site Admin
Posts: 300
Joined: Thu 29 Dec 2005 23:22
Location: Axbridge, Somerset, UK

Re: Query on FTP file formats

Post by David Cooke » Fri 11 Jan 2013 14:03

They can do.

FTP can work in two modes, binary or ASCII format. In ASCII mode the end of line character is converted as appropriate to the destination computer's operating system - which is what you are seeing (LF becomes CRLF or vice versa).

In binary mode no translation occurs. The ftp client will make the decision as to which mode to be in. Check to see what is set in your options. It can be 'auto' based on file type or explicitly set to always be binary or always be ASCII.

I generally force everything to be binary so my binary files can't be accidentally corrupted and use a decent text editor that can cope with either ending for the text files.
Dave Cooke
BCA IT Working Party, BCA Web Services, National Cave Registry Co-ordinator, CSCC Webmaster

User avatar
David Gibson
Posts: 485
Joined: Thu 16 Mar 2006 23:45

Re: Query on FTP file formats

Post by David Gibson » Fri 11 Jan 2013 14:34

Thanks for that, Cookie. I had assumed I was transferring everything in binary, but had also totally forgotten that the setting existed. I checked, and I was in Auto mode, and that is definitely what was causing the behavior I noticed. This explains another odd thing I had noticed...

I was puzzled (but not enough to investigate) why some files I downloaded always had unix-style endings and others had PC-style endings. My habit is is to store log data on the server in files with extension .txp which is associated on my PC with TextPad. But, of course, TXP is not in the default list of file extensions to be transferred in ascii mode [my FTP package allows me to edit that list]. Hence my puzzlement over the difference in TXT and TXP files.

Post Reply