libftp.size function gives wrong results!

Peter Hansen peter at engcorp.com
Sun Jun 9 19:02:17 CEST 2002


Michael Davis wrote:
> 
> I'm writing a python program which will upload or download files via ftp.
> It's intended to be used to deploy a web site from a local machine to a
> server. It tries to determine which files are modified on the local machine
> by comparing file sizes and modification times.
> 
> I try to compare files using os.stat for the local file and FTP.size for the
> remote. The problem is, FTP.size is giving me incorrect results. If I use
> the ftp command line client, and look at one of my files on the server (the
> output looks like 'ls -l') then I can see that the file size, is, say,
> 1200. But the FTP.size function returns, say, 1242. 

I think you'll find the number of lines in that file is 42.  The difference
is probably between CRLF and LF line terminations in the file.  If you
transfer files with FTP and want to preserve the line endings, you have
to specify the binary type, not ascii.  Don't know how to do this with
ftplib, but from the ftp command line you would use 'type binary' or
'type ascii' to switch.

-Peter



More information about the Python-list mailing list