Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.0

Bug #1176 Net_FTP::ls can return dates in the future
Submitted: 2004-04-10 16:25 UTC
From: philip at philipnet dot com Assigned: toby
Status: Closed Package: Net_FTP
PHP Version: 4.3.4 OS: Linux 2.4.25
Roadmaps: (Not assigned)    

 [2004-04-10 16:25 UTC] philip at philipnet dot com
Description: ------------ Net_FTP::ls can return a timestamp value for a file which is in the future. This only occurs if the FTP site does not send Year information for its files and the files have a later date (wtr. month, day etc.) than the current date and time. Reproduce code: --------------- Apologies for the length <?php require_once 'Net/FTP.php'; $ftp = new Net_FTP( ); $ftp -> connect( ''); $ftp -> login ( 'anonymous'); $dir = $ftp->ls( '/'); $theone = array( ); foreach ($dir as $entry) { echo $entry["name"]; if (ereg("libxml2-[0-9].[0-9].[0-9].tar.gz", $entry["name"])) { echo " ".$theone["date"] ." ".$entry["date"]; if ($theone["date"] < $entry["date"]) { $theone = $entry; echo " match"; } } echo "\n"; } if ($theone["name"]=="") { echo "Unable to find file which maches ".$file."\n"; exit (1); } echo "The latest release is ".$theone["name"]."\n"; ?> Expected result: ---------------- Doing a Net_FTP::ls to should return a timestamp indicating that libxml2-2.68.tar.gz is later than libxml2-2.6.4.tar.gz, but it doesn't. Below is my proposed solution. It checks for timestamps from the future and recalculates the value if so. There might be a quicker way to do it - by subtracting the equivalent of a year from $out, but you would have to take leap years into account. Actual result: -------------- Proposed solution: function _parse_Date ( $date ) { // Sep 10 22:06 => Sep 10, <year> 22:06 if (preg_match("/([A-Za-z]+)[ ]+([0-9]+)[ ]+([0-9]+):([0-9]+)/", $date, $res)) { $year = date("Y"); $month = $res[1]; $day = $res[2]; $hour = $res[3]; $minute = $res[4]; $date = "$month $day, $year $hour:$minute"; $out = strtotime($date); if ($out > time()) { // We can't have a file with a timestamp in the future $year = date("Y")-; $month = $res[1]; $day = $res[2]; $hour = $res[3]; $minute = $res[4]; $date = "$month $day, $year $hour:$minute"; $out = strtotime($date); } } else { $out = strtotime($date); } if (!$out) { return $this->raiseError("Dateconversion faild.", 0); } return $out; }


 [2004-04-10 18:36 UTC] philip at philipnet dot com
Opps! $year = date("Y")-; should be: $year = date("Y")-1;
 [2004-04-12 09:50 UTC] philip at philipnet dot com
And the duplicate assignments don't need to be there as well!
 [2004-06-14 20:30 UTC] toby
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on In case this was a website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.