FTP file creation date

G?nter Jantzen guenter.jantzen at t-mobile.de
Fri Oct 29 13:26:22 EDT 2004


eugene at boardkulture.com ([ EuGeNe ]) 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).
> 
> Any idea?
> 
> Thanks for your help!
> 
> EuGeNe

import os, ftplib, time 

#==============================================================================
thisyear =  time.localtime().tm_year
monthdict={'Jan': 1,'Feb': 2,'Mar': 3,'Apr': 4,'May': 5,'Jun':
6,'Jul': 7,'Aug': 8,'Sep': 9,'Oct': 10,'Nov': 11,'Dec':12}
#==============================================================================
def listdir(ftp, path = '.'):
    filetimes={}
    #-------------------   
    def callback(line): 
        ls = line.split()
        #print ls ->  ['drwxrwxr-x', '2', 'ftpclient', 'k3', '335872',
'Jul', '23', '15:31', 'trash_check']
        if len(ls) == 9: 
            access, x, y, z, size, ls_month, ls_day, ls_union,
ls_filename = ls
            tm_mon = monthdict[ls_month]
            tm_mday   = int(ls_day)
            assert len(ls_union) in (4,5)
            if len(ls_union) == 5:
                assert ls_union[2] == ':' 
                tm_year = thisyear
                tm_hour, tm_min =
int(ls_union[0:2]),int(ls_union[3:5])
            elif len(ls_union) == 4:
                tm_year = int(ls_union)
                tm_hour, tm_min = 0, 0

            ftime = time.mktime((tm_year, tm_mon, tm_mday, tm_hour,
tm_min, 0,0,0,-1))
            filetimes[ls_filename] = ftime
    #------------------        
    ftp.dir(path, callback)
    return filetimes



More information about the Python-list mailing list