Changes from branches/4.3/src/wp-admin/includes/class-ftp.php at r62767 to trunk/src/wp-admin/includes/class-ftp.php at r62767
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/class-ftp.php (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-ftp.php
r62767 r62767 1 1 <?php 2 2 /** 3 * PemFTP - A Ftp implementation in pure PHP3 * PemFTP - An Ftp implementation in pure PHP 4 4 * 5 5 * @package PemFTP 6 * @since 2.5 6 * @since 2.5.0 7 7 * 8 8 * @version 1.0 9 9 * @copyright Alexey Dotsenko 10 10 * @author Alexey Dotsenko 11 * @link http ://www.phpclasses.org/browse/package/1743.html Site12 * @license LGPL http ://www.opensource.org/licenses/lgpl-license.html11 * @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html 12 * @license LGPL https://opensource.org/licenses/lgpl-license.html 13 13 */ 14 14 … … 18 18 * This can be redefined. 19 19 * 20 * @since 2.5 20 * @since 2.5.0 21 21 * @var string 22 22 */ 23 if(!defined('CRLF')) define('CRLF',"\r\n"); 23 if ( ! defined( 'CRLF' ) ) { 24 define( 'CRLF', "\r\n" ); 25 } 24 26 25 27 /** … … 28 30 * This can be redefined. 29 31 * 30 * @since 2.5 32 * @since 2.5.0 31 33 * @var int 32 34 */ 33 if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1); 35 if ( ! defined( 'FTP_AUTOASCII' ) ) { 36 define( 'FTP_AUTOASCII', -1 ); 37 } 34 38 35 39 /** 36 40 * 37 41 * This can be redefined. 38 * @since 2.5 42 * @since 2.5.0 39 43 * @var int 40 44 */ 41 if(!defined("FTP_BINARY")) define("FTP_BINARY", 1); 45 if ( ! defined( 'FTP_BINARY' ) ) { 46 define( 'FTP_BINARY', 1 ); 47 } 42 48 43 49 /** 44 50 * 45 51 * This can be redefined. 46 * @since 2.5 52 * @since 2.5.0 47 53 * @var int 48 54 */ 49 if(!defined("FTP_ASCII")) define("FTP_ASCII", 0); 55 if ( ! defined( 'FTP_ASCII' ) ) { 56 define( 'FTP_ASCII', 0 ); 57 } 50 58 51 59 /** … … 54 62 * This can be redefined. 55 63 * 56 * @since 2.5 64 * @since 2.5.0 57 65 * @var bool 58 66 */ 59 if(!defined('FTP_FORCE')) define('FTP_FORCE', true); 67 if ( ! defined( 'FTP_FORCE' ) ) { 68 define( 'FTP_FORCE', true ); 69 } 60 70 61 71 /** 62 * @since 2.5 72 * @since 2.5.0 63 73 * @var string 64 74 */ … … 66 76 67 77 /** 68 * @since 2.5 78 * @since 2.5.0 69 79 * @var string 70 80 */ … … 72 82 73 83 /** 74 * @since 2.5 84 * @since 2.5.0 75 85 * @var string 76 86 */ … … 149 159 $this->OS_local=FTP_OS_Unix; 150 160 $this->OS_remote=FTP_OS_Unix; 151 $this->features=array();152 161 if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows; 153 162 elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac; … … 186 195 if ($lcount<8) return ''; 187 196 $b = array(); 188 $b['isdir'] = $lucifer[0] {0}=== "d";189 $b['islink'] = $lucifer[0] {0}=== "l";197 $b['isdir'] = $lucifer[0][0] === "d"; 198 $b['islink'] = $lucifer[0][0] === "l"; 190 199 if ( $b['isdir'] ) 191 200 $b['type'] = 'd'; … … 208 217 $b['day'] = $lucifer[6]; 209 218 if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) { 210 $b['year'] = date("Y");219 $b['year'] = gmdate("Y"); 211 220 $b['hour'] = $l2[1]; 212 221 $b['minute'] = $l2[2]; … … 270 279 271 280 function SetServer($host, $port=21, $reconnect=true) { 272 if(!is_ long($port)) {281 if(!is_int($port)) { 273 282 $this->verbose=true; 274 283 $this->SendMSG("Incorrect port syntax"); … … 335 344 $this->_ready=true; 336 345 $syst=$this->systype(); 337 if(!$syst) $this->SendMSG("Can 't detect remote OS");346 if(!$syst) $this->SendMSG("Cannot detect remote OS"); 338 347 else { 339 348 if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows; … … 343 352 $this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]); 344 353 } 345 if(!$this->features()) $this->SendMSG("Can 't get features list. All supported - disabled");354 if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled"); 346 355 else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features))); 347 356 return TRUE; … … 372 381 $this->SendMSG("Authentication succeeded"); 373 382 if(empty($this->_features)) { 374 if(!$this->features()) $this->SendMSG("Can 't get features list. All supported - disabled");383 if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled"); 375 384 else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features))); 376 385 } … … 381 390 if(!$this->_exec("PWD", "pwd")) return FALSE; 382 391 if(!$this->_checkCode()) return FALSE; 383 return ereg_replace("^[0-9]{3} \"(.+)\".+", "\\1", $this->_message);392 return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message); 384 393 } 385 394 … … 425 434 if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE; 426 435 if(!$this->_checkCode()) return FALSE; 427 return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);436 return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message); 428 437 } 429 438 … … 445 454 if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE; 446 455 if(!$this->_checkCode()) return FALSE; 447 $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);456 $mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message); 448 457 $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d"); 449 458 $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]); … … 481 490 } 482 491 if($this->_curtype!=FTP_BINARY) { 483 $this->PushError("restore", "can 't restore in ASCII mode");484 return FALSE; 485 } 486 if(!$this->_exec("REST ".$from, "res ore")) return FALSE;492 $this->PushError("restore", "cannot restore in ASCII mode"); 493 return FALSE; 494 } 495 if(!$this->_exec("REST ".$from, "restore")) return FALSE; 487 496 if(!$this->_checkCode()) return FALSE; 488 497 return TRUE; … … 525 534 } 526 535 527 function fget($fp, $remotefile, $rest=0) {536 function fget($fp, $remotefile, $rest=0) { 528 537 if($this->_can_restore and $rest!=0) fseek($fp, $rest); 529 538 $pi=pathinfo($remotefile); … … 554 563 $fp = @fopen($localfile, "w"); 555 564 if (!$fp) { 556 $this->PushError("get","can 't open local file", "Cannot create \"".$localfile."\"");565 $this->PushError("get","cannot open local file", "Cannot create \"".$localfile."\""); 557 566 return FALSE; 558 567 } … … 584 593 } 585 594 586 function fput($remotefile, $fp ) {595 function fput($remotefile, $fp, $rest=0) { 587 596 if($this->_can_restore and $rest!=0) fseek($fp, $rest); 588 597 $pi=pathinfo($remotefile); … … 611 620 if(is_null($remotefile)) $remotefile=$localfile; 612 621 if (!file_exists($localfile)) { 613 $this->PushError("put","can 't open local file", "No such file or directory \"".$localfile."\"");622 $this->PushError("put","cannot open local file", "No such file or directory \"".$localfile."\""); 614 623 return FALSE; 615 624 } … … 617 626 618 627 if (!$fp) { 619 $this->PushError("put","can 't open local file", "Cannot read file \"".$localfile."\"");628 $this->PushError("put","cannot open local file", "Cannot read file \"".$localfile."\""); 620 629 return FALSE; 621 630 } … … 650 659 $local=realpath($local); 651 660 if(!@file_exists($local)) { 652 $this->PushError("mput","can 't open local folder", "Cannot stat folder \"".$local."\"");661 $this->PushError("mput","cannot open local folder", "Cannot stat folder \"".$local."\""); 653 662 return FALSE; 654 663 } … … 663 672 closedir($handle); 664 673 } else { 665 $this->PushError("mput","can 't open local folder", "Cannot read folder \"".$local."\"");674 $this->PushError("mput","cannot open local folder", "Cannot read folder \"".$local."\""); 666 675 return FALSE; 667 676 } … … 683 692 $list=$this->rawlist($remote, "-lA"); 684 693 if($list===false) { 685 $this->PushError("mget","can 't read remote folder list", "Can't read remote folder \"".$remote."\" contents");694 $this->PushError("mget","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents"); 686 695 return FALSE; 687 696 } … … 689 698 if(!@file_exists($local)) { 690 699 if(!@mkdir($local)) { 691 $this->PushError("mget","can 't create local folder", "Cannot create folder \"".$local."\"");700 $this->PushError("mget","cannot create local folder", "Cannot create folder \"".$local."\""); 692 701 return FALSE; 693 702 } … … 695 704 foreach($list as $k=>$v) { 696 705 $list[$k]=$this->parselisting($v); 697 if( $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);706 if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]); 698 707 } 699 708 $ret=true; … … 701 710 if($el["type"]=="d") { 702 711 if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) { 703 $this->PushError("mget", "can 't copy folder", "Can't copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");712 $this->PushError("mget", "cannot copy folder", "Cannot copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\""); 704 713 $ret=false; 705 714 if(!$continious) break; … … 707 716 } else { 708 717 if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) { 709 $this->PushError("mget", "can 't copy file", "Can't copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");718 $this->PushError("mget", "cannot copy file", "Cannot copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\""); 710 719 $ret=false; 711 720 if(!$continious) break; … … 722 731 $list=$this->rawlist($remote, "-la"); 723 732 if($list===false) { 724 $this->PushError("mdel","can 't read remote folder list", "Can't read remote folder \"".$remote."\" contents");733 $this->PushError("mdel","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents"); 725 734 return false; 726 735 } … … 728 737 foreach($list as $k=>$v) { 729 738 $list[$k]=$this->parselisting($v); 730 if( $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);739 if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]); 731 740 } 732 741 $ret=true; … … 743 752 } else { 744 753 if (!$this->delete($remote."/".$el["name"])) { 745 $this->PushError("mdel", "can 't delete file", "Can't delete remote file \"".$remote."/".$el["name"]."\"");754 $this->PushError("mdel", "cannot delete file", "Cannot delete remote file \"".$remote."/".$el["name"]."\""); 746 755 $ret=false; 747 756 if(!$continious) break; … … 751 760 752 761 if(!$this->rmdir($remote)) { 753 $this->PushError("mdel", "can 't delete folder", "Can't delete remote folder \"".$remote."/".$el["name"]."\"");762 $this->PushError("mdel", "cannot delete folder", "Cannot delete remote folder \"".$remote."/".$el["name"]."\""); 754 763 $ret=false; 755 764 } … … 776 785 } else $path=getcwd(); 777 786 if(is_array($handle) and !empty($handle)) { 778 while($dir=each($handle)) {787 foreach($handle as $dir) { 779 788 if($this->glob_pattern_match($pattern,$dir)) 780 789 $output[]=$dir; … … 793 802 } 794 803 795 function glob_pattern_match($pattern,$s tring) {804 function glob_pattern_match($pattern,$subject) { 796 805 $out=null; 797 806 $chunks=explode(';',$pattern); 798 807 foreach($chunks as $pattern) { 799 808 $escape=array('$','^','.','{','}','(',')','[',']','|'); 800 while(str pos($pattern,'**')!==false)809 while(str_contains($pattern,'**')) 801 810 $pattern=str_replace('**','*',$pattern); 802 811 foreach($escape as $probe) … … 808 817 $out[]=$pattern; 809 818 } 810 if(count($out)==1) return($this->glob_regexp("^$out[0]$",$s tring));819 if(count($out)==1) return($this->glob_regexp("^$out[0]$",$subject)); 811 820 else { 812 821 foreach($out as $tester) 813 if($this->my_regexp("^$tester$",$string)) return true; 822 // TODO: This should probably be glob_regexp(), but needs tests. 823 if($this->my_regexp("^$tester$",$subject)) return true; 814 824 } 815 825 return false; 816 826 } 817 827 818 function glob_regexp($pattern,$ probe) {828 function glob_regexp($pattern,$subject) { 819 829 $sensitive=(PHP_OS!='WIN32'); 820 830 return ($sensitive? 821 ereg($pattern,$probe):822 eregi($pattern,$probe)831 preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $subject ) : 832 preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $subject ) 823 833 ); 824 834 } … … 827 837 $list=$this->rawlist($remote, "-la"); 828 838 if($list===false) { 829 $this->PushError("dirlist","can 't read remote folder list", "Can't read remote folder \"".$remote."\" contents");839 $this->PushError("dirlist","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents"); 830 840 return false; 831 841 } … … 900 910 if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) { 901 911 $prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : ''; 902 @dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); 912 @dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.dlDeprecated 903 913 $mod_sockets = extension_loaded( 'sockets' ); 904 914 } 905 915 906 require_once dirname( __FILE__ ) . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php"; 916 require_once __DIR__ . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php"; 917 918 if ( $mod_sockets ) { 919 class ftp extends ftp_sockets {} 920 } else { 921 class ftp extends ftp_pure {} 922 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)