Patch to LWP::Protocol::ftp to return last modified time
Charles C. Fu (ccwf@bacchus.com)
Thu, 2 Jul 1998 19:25:41 -0700
This small patch retrieves last modified information for files on FTP
servers using the MDTM command described in the IETF's draft FTP
extensions (available at
http://www.ietf.org/internet-drafts/draft-ietf-ftpext-mlst-04.txt).
Last modification information may be useful for those wishing to
implement caching for FTP URLs.
BSD-based FTP daemons correctly implement this command and account for
a large percentage (most, I believe) of the major FTP servers on the
Internet, so this modification should be immediately useful. Some
rudimentary checking is done on the results of the MDTM command, and
no last modified header is generated if the server does not support
the command or sends back a non-standard reply.
Unfortunately, there are some FTP servers which incorrectly return
time using the local time zone instead of UCT, which will cause the
last modified header to be off by that amount. There's probably no
workaround except to make a list of such servers and deal with them in
some fashion (ugh). I doubt this is worth the effort.
One day, last modification time (and a lot of other information like
file listings, MIME type, and maybe canonicalized pathnames and unique
file IDs) should be retrieved via the new proposed MLST, MLSD, and
other commands. However, these extensions are not widely implemented
at this time, so there is no hurry.
-ccwf
Charles C. Fu
===============================================================================
*** ftp.pm Fri Dec 12 07:49:31 1997
--- ftpext.pm Thu Jul 2 18:52:16 1998
***************
*** 8,13 ****
--- 8,14 ----
use Carp ();
+ use HTTP::Date();
use HTTP::Status ();
use HTTP::Negotiate ();
use HTTP::Response ();
***************
*** 134,140 ****
--- 135,150 ----
}
if ($method eq 'GET' || $method eq 'HEAD') {
+ LWP::Debug::debug("MDTM");
+ if($ftp->mdtm($remote_file) && $ftp->message =~ /^[1-9]\d{11}(.\d*)?$/)
+ {
+ $response->last_modified(
+ HTTP::Date::str2time(substr($ftp->message, 0, 8) . 'T'
+ . substr($ftp->message, 8) . 'Z'));
+ }
+
my $data; # the data handle
+
LWP::Debug::debug("retrieve file?");
if (length($remote_file) and $data = $ftp->retr($remote_file)) {
my($type, @enc) = LWP::MediaTypes::guess_media_type($remote_file);