Re: Patch to LWP::Protocol::ftp to return last modified time
Gisle Aas (gisle@aas.no)
05 Jul 1998 21:35:21 +0200
"Charles C. Fu" <ccwf@bacchus.com> writes:
> 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.
Thank you!
I modified your patch so it also support If-Modified-Since in the
request. Modified patch included. It will be in the next LWP
release, and LWPng already support MDTM for FTP.
> 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.
I say we just ignore this problem. Let's trust the servers to give us
correct information. If you do a mirror application it will probably
not matter as the server give you the same wrong numbers each time
(unless DST status has changed since last fetch.)
> 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.
I wish there was some nice way to implement HEAD request towards FTP
servers. If I remember correctly the problem was that MDTM will
return the same response if you try in on a directory as if you try it
on an non-existing file. Will MLST/MLSD help that?
Regards,
Gisle
Index: lib/LWP/Protocol/ftp.pm
===================================================================
RCS file: /home/cvs/aas/perl/mods/libwww-perl/lib/LWP/Protocol/ftp.pm,v
retrieving revision 1.20
diff -u -u -r1.20 ftp.pm
--- ftp.pm 1997/12/12 15:49:31 1.20
+++ ftp.pm 1998/07/05 19:19:09
@@ -8,6 +8,7 @@
use Carp ();
+use HTTP::Date();
use HTTP::Status ();
use HTTP::Negotiate ();
use HTTP::Response ();
@@ -134,6 +135,23 @@
}
if ($method eq 'GET' || $method eq 'HEAD') {
+ LWP::Debug::debug("MDTM");
+ if($ftp->mdtm($remote_file)) {
+ my $mess = $ftp->message;
+ if ($mess =~ /^(\d{8})(\d{6})\d*$/) {
+ my $mod_time = HTTP::Date::str2time("$1T$2Z");
+ $response->last_modified($mod_time);
+ if (my $ims = $request->if_modified_since) {
+ LWP::Debug::debug("IMS: $ims");
+ if ($mod_time > $ims) {
+ $response->code(&HTTP::Status::RC_NOT_MODIFIED);
+ $response->message("Not modified");
+ return $response;
+ }
+ }
+ }
+ }
+
my $data; # the data handle
LWP::Debug::debug("retrieve file?");
if (length($remote_file) and $data = $ftp->retr($remote_file)) {