Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all.

I'm writing a FTP client in Perl. As a safety check I want to ensure I only download those files that have not been modified in, say, 900 seconds. To determine the age of the file I'm running a FTP dir list through File::Listing's parse_dir function. I then compare the diffrence between the current time and the last modified time of the file to see if I should download it or not. This works like a charm for all my local servers because the local time is the same on each server.

When I run my prog to grab files from a few remote servers I'm running into problems because the local time (and hence last mod time) on those servers varies depending on timezone. The last mod time (returned from parse_dir) is sometimes a time in the future (when compared with my localtime).

To be honest, I'm stumped as to proceed.

Any help at this point would be great!

Replies are listed 'Best First'.
Re: Remote File - Last Modification Time
by theorbtwo (Prior) on Jan 05, 2003 at 07:31 UTC

    I see three solutions, in order of knowlege of the server required:

    1: Take all times mod. one hour -- that is, compare based only on minutes and seconds. This will give odd results fairly often -- use it only if you know you'll be running often.

    2: Put the offset from GMT (or your localtime) in a config file for each server.

    3: Create a file on the server, then use it's time as your "now".

    Hm, I just thought of a number four: if the server also has a HTTP server on it, send a request, and guess off of the Date: header returned. That is, of course, rather fragile, but it's better then nothing.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      I would try the daytime (13/tcp) service before attempting to hit a web server. Web services are likely to be proxied.

      $ telnet xxx daytime Trying 192.168.80.3... Connected to xxx. Escape character is '^]'. 05 JAN 2003 11:16:39 EST Connection closed by foreign host.
      --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';