wp/wp-admin/includes/class-ftp.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * PemFTP - A Ftp implementation in pure PHP
     3  * PemFTP - An Ftp implementation in pure PHP
     4  *
     4  *
     5  * @package PemFTP
     5  * @package PemFTP
     6  * @since 2.5
     6  * @since 2.5.0
     7  *
     7  *
     8  * @version 1.0
     8  * @version 1.0
     9  * @copyright Alexey Dotsenko
     9  * @copyright Alexey Dotsenko
    10  * @author Alexey Dotsenko
    10  * @author Alexey Dotsenko
    11  * @link http://www.phpclasses.org/browse/package/1743.html Site
    11  * @link http://www.phpclasses.org/browse/package/1743.html Site
    15 /**
    15 /**
    16  * Defines the newline characters, if not defined already.
    16  * Defines the newline characters, if not defined already.
    17  *
    17  *
    18  * This can be redefined.
    18  * This can be redefined.
    19  *
    19  *
    20  * @since 2.5
    20  * @since 2.5.0
    21  * @var string
    21  * @var string
    22  */
    22  */
    23 if(!defined('CRLF')) define('CRLF',"\r\n");
    23 if(!defined('CRLF')) define('CRLF',"\r\n");
    24 
    24 
    25 /**
    25 /**
    26  * Sets whatever to autodetect ASCII mode.
    26  * Sets whatever to autodetect ASCII mode.
    27  *
    27  *
    28  * This can be redefined.
    28  * This can be redefined.
    29  *
    29  *
    30  * @since 2.5
    30  * @since 2.5.0
    31  * @var int
    31  * @var int
    32  */
    32  */
    33 if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
    33 if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
    34 
    34 
    35 /**
    35 /**
    36  *
    36  *
    37  * This can be redefined.
    37  * This can be redefined.
    38  * @since 2.5
    38  * @since 2.5.0
    39  * @var int
    39  * @var int
    40  */
    40  */
    41 if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
    41 if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
    42 
    42 
    43 /**
    43 /**
    44  *
    44  *
    45  * This can be redefined.
    45  * This can be redefined.
    46  * @since 2.5
    46  * @since 2.5.0
    47  * @var int
    47  * @var int
    48  */
    48  */
    49 if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
    49 if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
    50 
    50 
    51 /**
    51 /**
    52  * Whether to force FTP.
    52  * Whether to force FTP.
    53  *
    53  *
    54  * This can be redefined.
    54  * This can be redefined.
    55  *
    55  *
    56  * @since 2.5
    56  * @since 2.5.0
    57  * @var bool
    57  * @var bool
    58  */
    58  */
    59 if(!defined('FTP_FORCE')) define('FTP_FORCE', true);
    59 if(!defined('FTP_FORCE')) define('FTP_FORCE', true);
    60 
    60 
    61 /**
    61 /**
    62  * @since 2.5
    62  * @since 2.5.0
    63  * @var string
    63  * @var string
    64  */
    64  */
    65 define('FTP_OS_Unix','u');
    65 define('FTP_OS_Unix','u');
    66 
    66 
    67 /**
    67 /**
    68  * @since 2.5
    68  * @since 2.5.0
    69  * @var string
    69  * @var string
    70  */
    70  */
    71 define('FTP_OS_Windows','w');
    71 define('FTP_OS_Windows','w');
    72 
    72 
    73 /**
    73 /**
    74  * @since 2.5
    74  * @since 2.5.0
    75  * @var string
    75  * @var string
    76  */
    76  */
    77 define('FTP_OS_Mac','m');
    77 define('FTP_OS_Mac','m');
    78 
    78 
    79 /**
    79 /**
   522 		if($exists) $this->SendMSG("Remote file ".$pathname." exists");
   522 		if($exists) $this->SendMSG("Remote file ".$pathname." exists");
   523 		else $this->SendMSG("Remote file ".$pathname." does not exist");
   523 		else $this->SendMSG("Remote file ".$pathname." does not exist");
   524 		return $exists;
   524 		return $exists;
   525 	}
   525 	}
   526 
   526 
   527 	function fget($fp, $remotefile,$rest=0) {
   527 	function fget($fp, $remotefile, $rest=0) {
   528 		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
   528 		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
   529 		$pi=pathinfo($remotefile);
   529 		$pi=pathinfo($remotefile);
   530 		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
   530 		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
   531 		else $mode=FTP_BINARY;
   531 		else $mode=FTP_BINARY;
   532 		if(!$this->_data_prepare($mode)) {
   532 		if(!$this->_data_prepare($mode)) {
   581 		if(!$this->_readmsg()) return FALSE;
   581 		if(!$this->_readmsg()) return FALSE;
   582 		if(!$this->_checkCode()) return FALSE;
   582 		if(!$this->_checkCode()) return FALSE;
   583 		return $out;
   583 		return $out;
   584 	}
   584 	}
   585 
   585 
   586 	function fput($remotefile, $fp) {
   586 	function fput($remotefile, $fp, $rest=0) {
   587 		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
   587 		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
   588 		$pi=pathinfo($remotefile);
   588 		$pi=pathinfo($remotefile);
   589 		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
   589 		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
   590 		else $mode=FTP_BINARY;
   590 		else $mode=FTP_BINARY;
   591 		if(!$this->_data_prepare($mode)) {
   591 		if(!$this->_data_prepare($mode)) {
   773 		if(!($lastpos===false)) {
   773 		if(!($lastpos===false)) {
   774 			$path=substr($pattern,0,-$lastpos-1);
   774 			$path=substr($pattern,0,-$lastpos-1);
   775 			$pattern=substr($pattern,$lastpos);
   775 			$pattern=substr($pattern,$lastpos);
   776 		} else $path=getcwd();
   776 		} else $path=getcwd();
   777 		if(is_array($handle) and !empty($handle)) {
   777 		if(is_array($handle) and !empty($handle)) {
   778 			while($dir=each($handle)) {
   778 			foreach($handle as $dir) {
   779 				if($this->glob_pattern_match($pattern,$dir))
   779 				if($this->glob_pattern_match($pattern,$dir))
   780 				$output[]=$dir;
   780 				$output[]=$dir;
   781 			}
   781 			}
   782 		} else {
   782 		} else {
   783 			$handle=@opendir($path);
   783 			$handle=@opendir($path);