FAQ
Hi,

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. This happens for all
the files, they're all reported to be about 5% larger than they really are.

Is there a better way of doing this, aside from capturing the output of
FTPLIB.dir (which goes to stdout) and parsing it?

Thanks in advance!
--
Michael Davis
Damaru
Custom Programming - Web Development - Database Design
http://www.damaru.com
416-540-1284

Search Discussions

  • Michael Davis at Jun 9, 2002 at 4:13 pm
    Hi,

    I just realized that this isn't a python question, it's an ftp question. I
    tried doing:

    size index.html

    from the ftp prompt, and it too gave me the wrong size!

    So I apologize for being off-topic. The trouble is, I can't seem to find a
    newsgroup specific to ftp problems. The existing ftp newsgroups seem to be
    just full of announcements about servers with adult content...

    Cheers,
    Michael

    Michael Davis wrote:
    Hi,

    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. This happens for
    all the files, they're all reported to be about 5% larger than they really
    are.

    Is there a better way of doing this, aside from capturing the output of
    FTPLIB.dir (which goes to stdout) and parsing it?

    Thanks in advance!
    --
    Michael Davis
    Damaru
    Custom Programming - Web Development - Database Design
    http://www.damaru.com
    416-540-1284
  • Peter Hansen at Jun 9, 2002 at 5:02 pm

    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
  • Michael Davis at Jun 9, 2002 at 5:07 pm

    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.

    Thanks again,

    --
    Michael Davis
    Damaru
    Custom Programming - Web Development - Database Design
    http://www.damaru.com
    416-540-1284
  • Steve Holden at Jun 14, 2002 at 2:50 am
    "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/
    -----------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 9, '02 at 3:51p
activeJun 14, '02 at 2:50a
posts5
users3
websitepython.org

People

Translate

site design / logo © 2021 Grokbase