FTP file creation date
Tim Williams
listserver at tdw.net
Wed Oct 27 12:03:39 EDT 2004
"[ EuGeNe ]" <eugene at boardkulture.com> wrote in message
news:de8687be.0410270727.12eb2d3b at posting.google.com...
> 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()
More information about the Python-list
mailing list