Re: [Patch] Net_FTP to allow Windows_NT ftp directories. Parser uses array callback.
| From: | Alan Knowles | Date: | Tue, 23 Dec 2003 11:46:42 +0000 |
| Subject: | Re: [Patch] Net_FTP to allow Windows_NT ftp directories. Parser uses array callback. | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24618@lists.php.net to get a copy of this message | ||
can you file a bug report (with a link to this post on news.php.net or marc.theaimsgroup)
That way it's less likely to get forgotten
Regards
Alan
Quilantang, Eric wrote:
--- FTP.php.bak 2003-12-22 11:42:18.989016000 -0600 +++ FTP.php 2003-12-22 12:07:30.883012800 -0600 @@ -123,6 +123,17 @@-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.comvar $_file_extensions; /** + * System type used by list parser + * + * System type used by list parser + * + * @access private + * @var string + */++ var $_systype;++ /** * This generates a new FTP-Object * This generates a new FTP-Object. The FTP-connection will not beestablished, yet.* You can leave $host and $port blank, if you want. The $host willnot be set @@ -220,6 +231,7 @@if (!$res) { return $this->raiseError("Unable to login", 0); } else { + $this->_systype = @ftp_systype($this->_handle); return true; } }@@ -909,6 +921,62 @@} /** + * UNIX + * 0 1 2 3 4 5 6 + * 0123456789012345678901234567890123456789012345678901234567890 + * drwxr-xr-x 2 user group 512 Dec 1 16:27 mm + * -r--r--r-- 1 user group 4038 Nov 12 14:15 patel + * + * @access private + * @param string $entry String entry + * @return array $entry Parsed entry + */++ function _list_and_parse_UNIX( &$entry ) + { + if (substr($entry,50,1)==':') { // if time + $stamp = strtotime(substr_replace(substr($entry, 41,12),date(' Y'),6,0));+ } else { + $stamp = strtotime(substr($entry, 41, 12)); + } + $date = date('Y-m-d H:i', $stamp); + $entry = array("name" => substr($entry, 54), + "size" => (int)substr($entry, 33, 7), + "rights" => substr($entry, 1, 9), + "user" => trim(substr($entry, 15, 8)), + "group" => trim(substr($entry, 24, 8)), + "files_inside" => (int)substr($entry, 11, 3), + "stamp" => $stamp, + "date" => $date, + "is_dir" => substr($entry, 0, 1)=='d'); + + } + + /** + * Windows_NT + * 0 1 2 3 4 5 6 + * 0123456789012345678901234567890123456789012345678901234567890 + * 05-27-03 02:09PM <DIR> analog + * 05-27-03 02:09PM 122058 c01lst.htm + * + * @access private + * @param string $entry String entry + * @return array $entry Parsed entry + */++ function _list_and_parse_Windows_NT( &$entry ) + { + $stamp = strtotime(str_replace('-','/',substr($entry, 0, 17))); + $date = date('Y-m-d H:i', $stamp); + $entry = array("name" => substr($entry, 39), + "size" => (int)substr($entry, 24, 14), + "stamp" => $stamp, + "date" => $date, + "is_dir" => substr($entry, 24, 5)=='<DIR>'); + } +++ /** * This lists up the directory-content and parses the items intowell-formated arrays* This lists up the directory-content and parses the items intowell-formated arrays* The results of this array are sorted (dirs on top, sorted byname; @@ -923,44 +991,17 @@$dirs_list = array(); $files_list = array(); $dir_list = ftp_rawlist($this->_handle, $dir);++ array_walk($dir_list, array(&$this,'_list_and_parse_'.$this->_systype)); +foreach ($dir_list as $entry) { - // ([1] = directory?, [2] = rights, [3] = files below, [4]= user,- // [5] = group, [6] = size, [7] = date, [8] = name) - $res_1 = @ereg(NET_FTP_DIR_EREG ,$entry,$eregs); - if (!$res_1) { - var_dump($entry); - return $this->raiseError("Raw directory-list in wrongformat.", 0);- } - $is_dir = (@trim($eregs[1]) == "d"); - // snip link-locations (have to clean that up later) - if (@trim($eregs[1]) == "l") { - preg_match("/(.*) -> (.*)/", $eregs[8], $matches); - $eregs[8] = $matches[1]; - } - - $date = $this->_parse_date($eregs[7]); - // $date = $eregs[7]; - if (!$date) { - return $this->raiseError("Can not parse date from rawdirectory-list on '$dir'.", 0);- } - if ($is_dir) { - $dirs_list[] = array("name" => $eregs[8], - "rights" => $eregs[2], - "user" => $eregs[4], - "group" => $eregs[5], - "files_inside" => $eregs[3], - "date" => $date, - "is_dir" => $is_dir); + if ($entry['is_dir']) { + $dirs_list[] = $entry; } else { - $files_list[] = array("name" => $eregs[8], - "size" => (int)$eregs[6], - "rights" => $eregs[2], - "user" => $eregs[4], - "group" => $eregs[5], - "date" => $date, - "is_dir" => $is_dir); + $files_list[] = $entry; } }+@usort($dirs_list, array("Net_FTP", "_nat_sort")); @usort($files_list, array("Net_FTP", "_nat_sort")); $res["dirs"] = $dirs_list;