[Tutor] Preserving timestamps when DLing with ftplib / gzip?

Terry Carroll carroll at tjc.com
Sun Nov 23 20:50:32 EST 2003

I have an application that uses a series of files that I need to refresh 
from an FTP server once in a while, to stay current.

When I do this manually, I use ncftp to FTP the six files, which are in
gzip form, and then gunzip them to another directory.

When I do this, the downloded .gz files have the same timestamp that they 
had on the server, and then the uncompressed files also have that same 

Rather than do this manually, I'm trying to use python to do this.

It's fairly straightforward, I find, to use the ftplib and gzip modules to 
do the transfer and decompress, respectively, but both the 
FTP'd files and the uncompressed files have the current timestamp, not the 
one from the server.   This is to be expected, since in both cases, I'm 
just opening the output files from within python.

I'd like to preserve that timestamp, the same way that the ncftp/gunzip 
manual process does.

Is there a way to do this?  I suppose I'd first have to somehow use ftplib 
to find out the timestamp on the remote file, and then use some sort of 
interface to set it on the files I create, right?

Or should I just give up on this and just invoke ncftp and gunzip from my 

I'm running WinXP.

Terry Carroll
Santa Clara, CA
carroll at tjc.com 

More information about the Tutor mailing list