3 * PemFTP - A Ftp implementation in pure PHP
9 * @copyright Alexey Dotsenko
10 * @author Alexey Dotsenko
11 * @link http://www.phpclasses.org/browse/package/1743.html Site
12 * @license LGPL License http://www.opensource.org/licenses/lgpl-license.html
14 if(!defined('CRLF')) define('CRLF',"\r\n");
15 if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
16 if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
17 if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
18 if(!defined('FTP_FORCE')) define('FTP_FORCE', TRUE);
19 define('FTP_OS_Unix','u');
20 define('FTP_OS_Windows','w');
21 define('FTP_OS_Mac','m');
24 /* Public variables */
30 /* Private variables */
42 var $_ftp_control_sock;
58 var $AuthorizedTransferMode;
64 function ftp_base($port_mode=FALSE) {
65 $this->__construct($port_mode);
68 function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
71 $this->_lastaction=NULL;
72 $this->_error_array=array();
73 $this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
74 $this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
75 $this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
76 $this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
77 $this->_port_available=($port_mode==TRUE);
78 $this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
79 $this->_connected=FALSE;
81 $this->_can_restore=FALSE;
84 $this->_ftp_buff_size=4096;
86 $this->SetUmask(0022);
87 $this->SetType(FTP_AUTOASCII);
88 $this->SetTimeout(30);
89 $this->Passive(!$this->_port_available);
90 $this->_login="anonymous";
91 $this->_password="anon@ftp.com";
92 $this->_features=array();
93 $this->OS_local=FTP_OS_Unix;
94 $this->OS_remote=FTP_OS_Unix;
95 $this->features=array();
96 if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
97 elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
100 // <!-- --------------------------------------------------------------------------------------- -->
101 // <!-- Public functions -->
102 // <!-- --------------------------------------------------------------------------------------- -->
104 function parselisting($line) {
105 $is_windows = ($this->OS_remote == FTP_OS_Windows);
106 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/",$line,$lucifer)) {
108 if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
109 $b['isdir'] = ($lucifer[7]=="<DIR>");
114 $b['size'] = $lucifer[7];
115 $b['month'] = $lucifer[1];
116 $b['day'] = $lucifer[2];
117 $b['year'] = $lucifer[3];
118 $b['hour'] = $lucifer[4];
119 $b['minute'] = $lucifer[5];
120 $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
121 $b['am/pm'] = $lucifer[6];
122 $b['name'] = $lucifer[8];
123 } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
125 $lcount=count($lucifer);
126 if ($lcount<8) return '';
128 $b['isdir'] = $lucifer[0]{0} === "d";
129 $b['islink'] = $lucifer[0]{0} === "l";
132 elseif ( $b['islink'] )
136 $b['perms'] = $lucifer[0];
137 $b['number'] = $lucifer[1];
138 $b['owner'] = $lucifer[2];
139 $b['group'] = $lucifer[3];
140 $b['size'] = $lucifer[4];
142 sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
143 sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
144 $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
145 $b['name'] = $lucifer[7];
147 $b['month'] = $lucifer[5];
148 $b['day'] = $lucifer[6];
149 if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
150 $b['year'] = date("Y");
152 $b['minute'] = $l2[2];
154 $b['year'] = $lucifer[7];
158 $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
159 $b['name'] = $lucifer[8];
166 function SendMSG($message = "", $crlf=true) {
167 if ($this->Verbose) {
168 echo $message.($crlf?CRLF:"");
174 function SetType($mode=FTP_AUTOASCII) {
175 if(!in_array($mode, $this->AuthorizedTransferMode)) {
176 $this->SendMSG("Wrong type");
180 $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
184 function _settype($mode=FTP_ASCII) {
186 if($mode==FTP_BINARY) {
187 if($this->_curtype!=FTP_BINARY) {
188 if(!$this->_exec("TYPE I", "SetType")) return FALSE;
189 $this->_curtype=FTP_BINARY;
191 } elseif($this->_curtype!=FTP_ASCII) {
192 if(!$this->_exec("TYPE A", "SetType")) return FALSE;
193 $this->_curtype=FTP_ASCII;
199 function Passive($pasv=NULL) {
200 if(is_null($pasv)) $this->_passive=!$this->_passive;
201 else $this->_passive=$pasv;
202 if(!$this->_port_available and !$this->_passive) {
203 $this->SendMSG("Only passive connections available!");
204 $this->_passive=TRUE;
207 $this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
211 function SetServer($host, $port=21, $reconnect=true) {
212 if(!is_long($port)) {
214 $this->SendMSG("Incorrect port syntax");
217 $ip=@gethostbyname($host);
218 $dns=@gethostbyaddr($host);
220 if(!$dns) $dns=$host;
221 if(ip2long($ip) === -1) {
222 $this->SendMSG("Wrong host name/address \"".$host."\"");
226 $this->_fullhost=$dns;
228 $this->_dataport=$port-1;
230 $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
232 if($this->_connected) {
233 $this->SendMSG("Reconnecting");
234 if(!$this->quit(FTP_FORCE)) return FALSE;
235 if(!$this->connect()) return FALSE;
241 function SetUmask($umask=0022) {
242 $this->_umask=$umask;
243 umask($this->_umask);
244 $this->SendMSG("UMASK 0".decoct($this->_umask));
248 function SetTimeout($timeout=30) {
249 $this->_timeout=$timeout;
250 $this->SendMSG("Timeout ".$this->_timeout);
251 if($this->_connected)
252 if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
256 function connect($server=NULL) {
257 if(!empty($server)) {
258 if(!$this->SetServer($server)) return false;
260 if($this->_ready) return true;
261 $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
262 if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
263 $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
266 $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
268 if(!$this->_readmsg()) return FALSE;
269 if(!$this->_checkCode()) return FALSE;
270 $this->_lastaction=time();
271 } while($this->_code<200);
273 $syst=$this->systype();
274 if(!$syst) $this->SendMSG("Can't detect remote OS");
276 if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
277 elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
278 elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
279 else $this->OS_remote=FTP_OS_Mac;
280 $this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
282 if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
283 else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
287 function quit($force=false) {
289 if(!$this->_exec("QUIT") and !$force) return FALSE;
290 if(!$this->_checkCode() and !$force) return FALSE;
292 $this->SendMSG("Session finished");
298 function login($user=NULL, $pass=NULL) {
299 if(!is_null($user)) $this->_login=$user;
300 else $this->_login="anonymous";
301 if(!is_null($pass)) $this->_password=$pass;
302 else $this->_password="anon@anon.com";
303 if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
304 if(!$this->_checkCode()) return FALSE;
305 if($this->_code!=230) {
306 if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
307 if(!$this->_checkCode()) return FALSE;
309 $this->SendMSG("Authentication succeeded");
310 if(empty($this->_features)) {
311 if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
312 else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
318 if(!$this->_exec("PWD", "pwd")) return FALSE;
319 if(!$this->_checkCode()) return FALSE;
320 return ereg_replace("^[0-9]{3} \"(.+)\".+", "\\1", $this->_message);
324 if(!$this->_exec("CDUP", "cdup")) return FALSE;
325 if(!$this->_checkCode()) return FALSE;
329 function chdir($pathname) {
330 if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
331 if(!$this->_checkCode()) return FALSE;
335 function rmdir($pathname) {
336 if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
337 if(!$this->_checkCode()) return FALSE;
341 function mkdir($pathname) {
342 if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
343 if(!$this->_checkCode()) return FALSE;
347 function rename($from, $to) {
348 if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
349 if(!$this->_checkCode()) return FALSE;
350 if($this->_code==350) {
351 if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
352 if(!$this->_checkCode()) return FALSE;
357 function filesize($pathname) {
358 if(!isset($this->_features["SIZE"])) {
359 $this->PushError("filesize", "not supported by server");
362 if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
363 if(!$this->_checkCode()) return FALSE;
364 return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
368 if(!$this->_exec("ABOR", "abort")) return FALSE;
369 if(!$this->_checkCode()) {
370 if($this->_code!=426) return FALSE;
371 if(!$this->_readmsg("abort")) return FALSE;
372 if(!$this->_checkCode()) return FALSE;
377 function mdtm($pathname) {
378 if(!isset($this->_features["MDTM"])) {
379 $this->PushError("mdtm", "not supported by server");
382 if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
383 if(!$this->_checkCode()) return FALSE;
384 $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
385 $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
386 $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
391 if(!$this->_exec("SYST", "systype")) return FALSE;
392 if(!$this->_checkCode()) return FALSE;
393 $DATA = explode(" ", $this->_message);
394 return array($DATA[1], $DATA[3]);
397 function delete($pathname) {
398 if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
399 if(!$this->_checkCode()) return FALSE;
403 function site($command, $fnction="site") {
404 if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
405 if(!$this->_checkCode()) return FALSE;
409 function chmod($pathname, $mode) {
410 if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
414 function restore($from) {
415 if(!isset($this->_features["REST"])) {
416 $this->PushError("restore", "not supported by server");
419 if($this->_curtype!=FTP_BINARY) {
420 $this->PushError("restore", "can't restore in ASCII mode");
423 if(!$this->_exec("REST ".$from, "resore")) return FALSE;
424 if(!$this->_checkCode()) return FALSE;
428 function features() {
429 if(!$this->_exec("FEAT", "features")) return FALSE;
430 if(!$this->_checkCode()) return FALSE;
431 $f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
432 $this->_features=array();
433 foreach($f as $k=>$v) {
434 $v=explode(" ", trim($v));
435 $this->_features[array_shift($v)]=$v;;
440 function rawlist($pathname="", $arg="") {
441 return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
444 function nlist($pathname="") {
445 return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
448 function is_exists($pathname) {
449 return $this->file_exists($pathname);
452 function file_exists($pathname) {
454 if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
456 if(!$this->_checkCode()) $exists=FALSE;
459 if($exists) $this->SendMSG("Remote file ".$pathname." exists");
460 else $this->SendMSG("Remote file ".$pathname." does not exist");
464 function fget($fp, $remotefile,$rest=0) {
465 if($this->_can_restore and $rest!=0) fseek($fp, $rest);
466 $pi=pathinfo($remotefile);
467 if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
468 else $mode=FTP_BINARY;
469 if(!$this->_data_prepare($mode)) {
472 if($this->_can_restore and $rest!=0) $this->restore($rest);
473 if(!$this->_exec("RETR ".$remotefile, "get")) {
474 $this->_data_close();
477 if(!$this->_checkCode()) {
478 $this->_data_close();
481 $out=$this->_data_read($mode, $fp);
482 $this->_data_close();
483 if(!$this->_readmsg()) return FALSE;
484 if(!$this->_checkCode()) return FALSE;
488 function get($remotefile, $localfile=NULL, $rest=0) {
489 if(is_null($localfile)) $localfile=$remotefile;
490 if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
491 $fp = @fopen($localfile, "w");
493 $this->PushError("get","can't open local file", "Cannot create \"".$localfile."\"");
496 if($this->_can_restore and $rest!=0) fseek($fp, $rest);
497 $pi=pathinfo($remotefile);
498 if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
499 else $mode=FTP_BINARY;
500 if(!$this->_data_prepare($mode)) {
504 if($this->_can_restore and $rest!=0) $this->restore($rest);
505 if(!$this->_exec("RETR ".$remotefile, "get")) {
506 $this->_data_close();
510 if(!$this->_checkCode()) {
511 $this->_data_close();
515 $out=$this->_data_read($mode, $fp);
517 $this->_data_close();
518 if(!$this->_readmsg()) return FALSE;
519 if(!$this->_checkCode()) return FALSE;
523 function fput($remotefile, $fp) {
524 if($this->_can_restore and $rest!=0) fseek($fp, $rest);
525 $pi=pathinfo($remotefile);
526 if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
527 else $mode=FTP_BINARY;
528 if(!$this->_data_prepare($mode)) {
531 if($this->_can_restore and $rest!=0) $this->restore($rest);
532 if(!$this->_exec("STOR ".$remotefile, "put")) {
533 $this->_data_close();
536 if(!$this->_checkCode()) {
537 $this->_data_close();
540 $ret=$this->_data_write($mode, $fp);
541 $this->_data_close();
542 if(!$this->_readmsg()) return FALSE;
543 if(!$this->_checkCode()) return FALSE;
547 function put($localfile, $remotefile=NULL, $rest=0) {
548 if(is_null($remotefile)) $remotefile=$localfile;
549 if (!file_exists($localfile)) {
550 $this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\"");
553 $fp = @fopen($localfile, "r");
556 $this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\"");
559 if($this->_can_restore and $rest!=0) fseek($fp, $rest);
560 $pi=pathinfo($localfile);
561 if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
562 else $mode=FTP_BINARY;
563 if(!$this->_data_prepare($mode)) {
567 if($this->_can_restore and $rest!=0) $this->restore($rest);
568 if(!$this->_exec("STOR ".$remotefile, "put")) {
569 $this->_data_close();
573 if(!$this->_checkCode()) {
574 $this->_data_close();
578 $ret=$this->_data_write($mode, $fp);
580 $this->_data_close();
581 if(!$this->_readmsg()) return FALSE;
582 if(!$this->_checkCode()) return FALSE;
586 function mput($local=".", $remote=NULL, $continious=false) {
587 $local=realpath($local);
588 if(!@file_exists($local)) {
589 $this->PushError("mput","can't open local folder", "Cannot stat folder \"".$local."\"");
592 if(!is_dir($local)) return $this->put($local, $remote);
593 if(empty($remote)) $remote=".";
594 elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
595 if($handle = opendir($local)) {
597 while (false !== ($file = readdir($handle))) {
598 if ($file != "." && $file != "..") $list[]=$file;
602 $this->PushError("mput","can't open local folder", "Cannot read folder \"".$local."\"");
605 if(empty($list)) return TRUE;
607 foreach($list as $el) {
608 if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
609 else $t=$this->put($local."/".$el, $remote."/".$el);
612 if(!$continious) break;
619 function mget($remote, $local=".", $continious=false) {
620 $list=$this->rawlist($remote, "-lA");
622 $this->PushError("mget","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
625 if(empty($list)) return true;
626 if(!@file_exists($local)) {
627 if(!@mkdir($local)) {
628 $this->PushError("mget","can't create local folder", "Cannot create folder \"".$local."\"");
632 foreach($list as $k=>$v) {
633 $list[$k]=$this->parselisting($v);
634 if($list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
637 foreach($list as $el) {
638 if($el["type"]=="d") {
639 if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
640 $this->PushError("mget", "can't copy folder", "Can't copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
642 if(!$continious) break;
645 if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
646 $this->PushError("mget", "can't copy file", "Can't copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
648 if(!$continious) break;
651 @chmod($local."/".$el["name"], $el["perms"]);
652 $t=strtotime($el["date"]);
653 if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
658 function mdel($remote, $continious=false) {
659 $list=$this->rawlist($remote, "-la");
661 $this->PushError("mdel","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
665 foreach($list as $k=>$v) {
666 $list[$k]=$this->parselisting($v);
667 if($list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
671 foreach($list as $el) {
675 if($el["type"]=="d") {
676 if(!$this->mdel($remote."/".$el["name"], $continious)) {
678 if(!$continious) break;
681 if (!$this->delete($remote."/".$el["name"])) {
682 $this->PushError("mdel", "can't delete file", "Can't delete remote file \"".$remote."/".$el["name"]."\"");
684 if(!$continious) break;
689 if(!$this->rmdir($remote)) {
690 $this->PushError("mdel", "can't delete folder", "Can't delete remote folder \"".$remote."/".$el["name"]."\"");
696 function mmkdir($dir, $mode = 0777) {
697 if(empty($dir)) return FALSE;
698 if($this->is_exists($dir) or $dir == "/" ) return TRUE;
699 if(!$this->mmkdir(dirname($dir), $mode)) return false;
700 $r=$this->mkdir($dir, $mode);
701 $this->chmod($dir,$mode);
705 function glob($pattern, $handle=NULL) {
707 if(PHP_OS=='WIN32') $slash='\\';
709 $lastpos=strrpos($pattern,$slash);
710 if(!($lastpos===false)) {
711 $path=substr($pattern,0,-$lastpos-1);
712 $pattern=substr($pattern,$lastpos);
713 } else $path=getcwd();
714 if(is_array($handle) and !empty($handle)) {
715 while($dir=each($handle)) {
716 if($this->glob_pattern_match($pattern,$dir))
720 $handle=@opendir($path);
721 if($handle===false) return false;
722 while($dir=readdir($handle)) {
723 if($this->glob_pattern_match($pattern,$dir))
728 if(is_array($output)) return $output;
732 function glob_pattern_match($pattern,$string) {
734 $chunks=explode(';',$pattern);
735 foreach($chunks as $pattern) {
736 $escape=array('$','^','.','{','}','(',')','[',']','|');
737 while(strpos($pattern,'**')!==false)
738 $pattern=str_replace('**','*',$pattern);
739 foreach($escape as $probe)
740 $pattern=str_replace($probe,"\\$probe",$pattern);
741 $pattern=str_replace('?*','*',
742 str_replace('*?','*',
743 str_replace('*',".*",
744 str_replace('?','.{1,1}',$pattern))));
747 if(count($out)==1) return($this->glob_regexp("^$out[0]$",$string));
749 foreach($out as $tester)
750 if($this->my_regexp("^$tester$",$string)) return true;
755 function glob_regexp($pattern,$probe) {
756 $sensitive=(PHP_OS!='WIN32');
758 ereg($pattern,$probe):
759 eregi($pattern,$probe)
763 function dirlist($remote) {
764 $list=$this->rawlist($remote, "-la");
766 $this->PushError("dirlist","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
771 foreach($list as $k=>$v) {
772 $entry=$this->parselisting($v);
776 if($entry["name"]=="." or $entry["name"]=="..")
779 $dirlist[$entry['name']] = $entry;
784 // <!-- --------------------------------------------------------------------------------------- -->
785 // <!-- Private functions -->
786 // <!-- --------------------------------------------------------------------------------------- -->
787 function _checkCode() {
788 return ($this->_code<400 and $this->_code>0);
791 function _list($arg="", $cmd="LIST", $fnction="_list") {
792 if(!$this->_data_prepare()) return false;
793 if(!$this->_exec($cmd.$arg, $fnction)) {
794 $this->_data_close();
797 if(!$this->_checkCode()) {
798 $this->_data_close();
802 if($this->_code<200) {
803 $out=$this->_data_read();
804 $this->_data_close();
805 if(!$this->_readmsg()) return FALSE;
806 if(!$this->_checkCode()) return FALSE;
807 if($out === FALSE ) return FALSE;
808 $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
809 // $this->SendMSG(implode($this->_eol_code[$this->OS_local], $out));
814 // <!-- --------------------------------------------------------------------------------------- -->
815 // <!-- Partie : gestion des erreurs -->
816 // <!-- --------------------------------------------------------------------------------------- -->
817 // Gnre une erreur pour traitement externe la classe
818 function PushError($fctname,$msg,$desc=false){
820 $error['time']=time();
821 $error['fctname']=$fctname;
823 $error['desc']=$desc;
824 if($desc) $tmp=' ('.$desc.')'; else $tmp='';
825 $this->SendMSG($fctname.': '.$msg.$tmp);
826 return(array_push($this->_error_array,$error));
829 // Rcupre une erreur externe
831 if(count($this->_error_array)) return(array_pop($this->_error_array));
837 if (!extension_loaded('sockets')) {
838 $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
839 if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE;
841 require_once "class-ftp-".($mod_sockets?"sockets":"pure").".php";