jdeuce jdeuce - 1 year ago 88
Python Question

how can I set the last modified time of a file from python?

I have a python script that downloads a file over FTP using ftplib.

My current download code looks just like the example in the ftp lib docs:

ftp.retrbinary('RETR README', open('README', 'wb').write)

Now I have a requirement that the file downloaded over FTP needs to have the same last modified time as the file on the FTP server itself. Assuming I could parse out the time from
, how can I set the modified time on the downloaded file?

I'm on a unix based OS if that matters.

Answer Source

If you want to do this directly from python, you're looking for os.utime. The docs can give you more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download