libftp.size function gives wrong results!

Steve Holden sholden at holdenweb.com
Thu Jun 13 22:50:54 EDT 2002


"Michael Davis" <michael at damaru.com> wrote ...
> Peter Hansen wrote:
>
> > 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.
>
> Thanks Peter,
>
> I had already thought of that. Both my local and the remote systems are
> unix, and so don't have CRs. But you're right - the difference in size is
> the same as the number of lines, as though the ftp size command assumed
> that I wanted to convert the end-of-lines to CRLF. I had specified binary
> mode transfers. And if I do 'ftp size' on true binary files, the same
> problem happens!
>
> Anyway, I just found out that one of the servers I need to talk to doesn't
> allow me to use 'size' anyway, so I'm going to ask a different python
> question in a different message.
>

You should take a look at "ftpmirror.py" in the Tools subdirectory of your
Python distribution.

Also, you might find it easier to use "make" to determoine what needs
uploading to you web system. This has worked very well for me.

regards
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list