| 
| Subject: | I had some troubles to use the... | 
|---|
 | Summary: | Package rating comment | 
|---|
 | Messages: | 2 | 
|---|
 | Author: | Christian Bode | 
|---|
 | Date: | 2008-06-04 23:36:36 | 
|---|
 | Update: | 2008-06-05 08:07:16 | 
|---|
 |  |  |  | 
Christian Bode rated this package as follows:
| Utility: | Good | 
|---|
| Consistency: | Good | 
|---|
| Documentation: | Sufficient | 
|---|
| Examples: | Sufficient | 
|---|
|  | 
  Christian Bode - 2008-06-04 23:36:36I had some troubles to use the function mdel with my win ftp server (SERV-U). The ftp server sends a additional line which is not covered by the regular expression in the beginning of the function parselisting so the return value $v in function parselisting isn't set (Error: Undefined variable: v)
 I soved this problem by predefine the return value $v in the beginning of the function parselisting.
 
 My new function parselisting:
 
 function parselisting($list) {
 //	Parses 1 line like:		"drwxrwx---  2 owner group 4096 Apr 23 14:57 text"
 $v=array(
 "type"	=> false,
 "perms"	=> false,
 "inode"	=> false,
 "owner"	=> false,
 "group"	=> false,
 "size"	=> false,
 "date"	=> false,
 "name"	=> false
 );
 
 if(preg_match("/^([-ld])([rwxst-]+)\s+(\d+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\w{3})\s+(\d+)\s+([\:\d]+)\s+(.+)$/i", $list, $ret)) {
 $v=array(
 "type"	=> ($ret[1]=="-"?"f":$ret[1]),
 "perms"	=> 0,
 "inode"	=> $ret[3],
 "owner"	=> $ret[4],
 "group"	=> $ret[5],
 "size"	=> $ret[6],
 "date"	=> $ret[7]." ".$ret[8]." ".$ret[9],
 "name"	=> $ret[10]
 );
 $bad=array("(?)");
 if(in_array($v["owner"], $bad)) $v["owner"]=NULL;
 if(in_array($v["group"], $bad)) $v["group"]=NULL;
 $v["perms"]+=00400*(int)($ret[2]{0}=="r");
 $v["perms"]+=00200*(int)($ret[2]{1}=="w");
 $v["perms"]+=00100*(int)in_array($ret[2]{2}, array("x","s"));
 $v["perms"]+=00040*(int)($ret[2]{3}=="r");
 $v["perms"]+=00020*(int)($ret[2]{4}=="w");
 $v["perms"]+=00010*(int)in_array($ret[2]{5}, array("x","s"));
 $v["perms"]+=00004*(int)($ret[2]{6}=="r");
 $v["perms"]+=00002*(int)($ret[2]{7}=="w");
 $v["perms"]+=00001*(int)in_array($ret[2]{8}, array("x","t"));
 $v["perms"]+=04000*(int)in_array($ret[2]{2}, array("S","s"));
 $v["perms"]+=02000*(int)in_array($ret[2]{5}, array("S","s"));
 $v["perms"]+=01000*(int)in_array($ret[2]{8}, array("T","t"));
 }
 return $v;
 }
 
 So the return value $v is always defined and has its indizes.
 
 You should adopt the function mdel to catch this case:
 
 function mdel($remote, $continious=false) {
 $list=$this->rawlist($remote, "-la");
 if($list===false) {
 $this->PushError("mdel","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
 return false;
 }
 
 foreach($list as $k=>$v) {
 
 $list[$k]=$this->parselisting($v);
 
 if($list[$k]["name"]=="." or $list[$k]["name"]==".." or $list[$k]["name"] === false) unset($list[$k]);
 }
 
 $ret=true;
 
 foreach($list as $el) {
 if($el["type"]=="d") {
 if(!$this->mdel($remote."/".$el["name"], $continious)) {
 $ret=false;
 if(!$continious) break;
 }
 } else {
 if (!$this->delete($remote."/".$el["name"])) {
 $this->PushError("mdel", "can't delete file", "Can't delete remote file \"".$remote."/".$el["name"]."\"");
 $ret=false;
 if(!$continious) break;
 }
 }
 }
 
 if(!$this->rmdir($remote)) {
 $this->PushError("mdel", "can't delete folder", "Can't delete remote folder \"".$remote."/".$el["name"]."\"");
 $ret=false;
 }
 return $ret;
 }
 
 By the way GREAT TOOL Alexey ;-)
  Alexey Dotsenko - 2008-06-05 08:07:16 - In reply to message 1 from Christian Bodemay it is better to do such way in "parselisting"
 if(preg_match("/^([-ld])([rwxst-]+)\s+(\d+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\w{3})\s+(\d+)\s+([\:\d]+)\s+(.+)$/i", $list, $ret)) {
 $v=array(
 "type" => ($ret[1]=="-"?"f":$ret[1]),
 "perms" => 0,
 "inode" => $ret[3],
 "owner" => $ret[4],
 "group" => $ret[5],
 "size" => $ret[6],
 "date" => $ret[7]." ".$ret[8]." ".$ret[9],
 "name" => $ret[10]
 ) else return null;
 
 and than in "mdel"
 
 if($list[$k]["name"]=="." or $list[$k]["name"]==".." or isnull($list[$k])) unset($list[$k]);
 |