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

I can get the Last Modification date on http page but not on a FTP page. Please advise if there is another method I can use to fetch Last Modification date on ftp web sites?
use LWP::Simple; use strict; use warnings; my $url = 'http://site/toyota.htm'; my ($lastMod) = (head($url))[2]; #This does work my $url2 = 'ftp://ftp.thesite.com/public/information/'; my ($lastMod2) = (head($url2))[2]; #This doesnt work print "$lastMod\n"; #Prints last mod date print "$lastMod2\n"; #Prints nothing

Replies are listed 'Best First'.
Re: Last Modification date
by Abigail-II (Bishop) on Oct 09, 2003 at 11:58 UTC
    While HTTP allows for a Last-Modified date header to be send, it's not required, and it's also not required to be the third line of the response, so I wouldn't say "# This does work". It's more "# It might work, sometimes, for some URLs".

    However, the FTP protocol doesn't send a Last-Modified piece of meta data, so you can't get it in the way you are trying. You *might* be able to get the information by using Net::FTP to log in to the server, cd to the appropriate directory, and issue a 'dir' command. You might be able to parse out the last modification date from the response - but then again, the server might not give it to you.

    It's important to realize that HTTP and FTP are two very different protocols.

    Abigail

      If you decide to go by the Net::FTP method here are somethings that might help you.

      And as Abigail-II says 'you might be able to get this information if your FTP server decides so'

      -T

      use perl; use strict;

      Thanks for the explanation.