Hi there everyone,
First of all, let me thank you for your always-present help in this list; I (as 
a newbie) appreciate it very much! :)
However, pardon me for I need to trouble you with another piece of text that 
doesn't do what it should do:
I need to parse the raw-listing of an FTP into it's parts (the code comes from 
the book published by Wrox, however, I don't have the book in my posession to 
check the two versions against each other), but it returns an empty list. Here 
is the code:
[code]
switch ($this->systype){ //Parse raw dir listing into fields
 case 'Windows_NT':  //Handle WinNT FTP servers
 $re = '/^.' .
 '([0-9-]+\s+)'.   //Get last mod date
 '\d\d:\d\d..)\s+' .  //Get last mod time
 '(\S+)\s+' .    //Get size or dir info
 '(.+)$/';    //Get file/dir name
 break;
 
 case 'UNIX':   //Handle UNIX FTP servers
 default:    //case UNIX falls through to default
  $re = '/'.   //Regax to parse common server dir into
  '^(.)' .   //Get entry type info (file/dir/etc.)
  '(\S+)\s+' .   //Get permissions info
  '\S+\s+'.   //Find, but don't capture hard link info
  '(\S+)\s+' .  //Get owner name
  '(\S+)\s+' .  //Get group name
  '(\S+)\s+' .  //Get size
  '(\S+\s+\S+\s+\S+\s+)' . //Get file/dir last mod time
  '(.+)$/';   //Get file/dir name
  break;
 }
 
 //Map short identifiers to full names
 $type = array('-'=>'file','d'=>'directory');
 
 $listing = array();
 
 foreach ($temp as $entry) {  //loop through raw listings
 //try to parse raw data into fields
 $match=preg_match($re,$entry,$matches);
 
  if(!$match) {   //if we could not parse the listings
  user_error("The directory listings could not be parsed.");
  return array();   
  }
 
 switch ($this->systypes){  //Give fileds sensible names
 case 'Windows_NT';    //Handle WinNT-style dir listings
  $listings[] = array( //Put parsed data into readable format
  'type' =>
    is_numeric($matches[2]) ? 'file' : 'directory','permissions' => 
null,'owner' =>NULL,'group'=>null,'size'=>(int)$matches[2],
    'last mod' => $matches[1],'name'=>$matches[3]);
 break;
 
 case 'UNIX':  //Handle UNIX FTP-style dir listings
 default:   //case UNIX fails through to default
 $strings[] = array( //Put data into readable format
 'type' =>$type[$matches[1]],'permissions' => $matches[2],'owner' 
=>$matches[3],'group' => $matches[4],'size' => $matches[5],
 'last mod' =>$matches[6],'name'=>$matches[7]);
 break;
  
 }
 } 
  return $listings;
[/code]

Since this function is called Is($directory); I tried this:
var_dump($ftp_server->Is($ftp_server->cwd));

However, I get null.

Why?

(It's not that I understand how the raw-listing is being parsed using regular 
expressions, so it's why I'm asking :) )

Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

Reply via email to