Re: FTP file creation date

Discussion in 'Python' started by Tim Williams, Oct 27, 2004.

  1. Tim Williams

    Tim Williams Guest

    "[ EuGeNe ]" <> wrote in message
    news:...
    > Hi all,
    >
    > I would like to write a script that downloads one file from a ftp
    > server if the file creation date satisfy a condition.
    >
    > I can't figure out how to find from a ftp server what is the creation
    > date of the file (using python).
    >


    Here's a snippet that does something based on size, the date can be
    retrieved by adapting the file.split() part in DoStuff ()
    (adapted from a snippet I found while googling once, I forget who to
    attribute it to - sorry )

    from ftplib import FTP
    # import os, sys

    files = ['file1.zip','file2.zip']
    get_list = []
    global progress

    def handleDownload(block):
    global progress
    file.write(block)
    progress = progress + len(block)
    print '\b'*20,progress,

    def doStuff(file):
    size = file.split()[4]
    name = file.split()[8]
    #
    # build a list of files to be downloaded using.
    # get_list.append(name)
    #

    if name in files :
    # if something else matches
    get_list.append(name)

    site = FTP('somedomain.com')
    #site.set_debuglevel(1)
    msg = site.login() #login (and store
    site.cwd('/pub')
    site.retrlines('LIST', doStuff)

    for x in range(len(get_list)):
    global progress
    progress = 0
    fname = get_list[x]
    print "downloading", fname
    file = open(('c:\\download\\' + fname), 'wb')
    site.retrbinary( "RETR " + fname, handleDownload )
    print
    file.close()

    site.quit()
     
    Tim Williams, Oct 27, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,285
    Michael Borgwardt
    May 30, 2004
  2. [ EuGeNe ]

    FTP file creation date

    [ EuGeNe ], Oct 27, 2004, in forum: Python
    Replies:
    5
    Views:
    1,453
    [ EuGeNe ]
    Oct 30, 2004
  3. ruby talk

    FTP folder creation mkdir problem

    ruby talk, Oct 20, 2004, in forum: Ruby
    Replies:
    3
    Views:
    362
    ruby talk
    Oct 20, 2004
  4. Jeff Miller
    Replies:
    0
    Views:
    513
    Jeff Miller
    Mar 26, 2009
  5. D. Buck
    Replies:
    2
    Views:
    501
    D. Buck
    Jun 29, 2004
Loading...

Share This Page