Make WordPress Core


Ignore:
Timestamp:
03/01/2008 09:20:23 PM (19 years ago)
Author:
ryan
Message:

Plugin updater updates. see #5586

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r7033 r7126  
    3030                if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
    3131                                return false;
    32                 $this->ftp = new FTP();
     32                $this->ftp = new ftp();
    3333
    3434                //Set defaults:
    … …  
    6161                if ( ! $this->ftp )
    6262                        return false;
    63                        
    64                 if ( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ) {
     63
     64                //$this->ftp->Verbose = true;
     65
     66                if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
     67                        $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
     68                        return false;
     69                }
     70                if ( ! $this->ftp->connect() ) {
    6571                        $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
    6672                        return false;
    … …  
    7278                }
    7379
     80                $this->ftp->SetType(FTP_AUTOASCII);
     81                $this->ftp->Passive(true);
    7482                return true;
    7583        }
    … …  
    114122                return $this->find_base_dir('/',$echo);
    115123        }
     124
    116125        function get_base_dir($base = '.'){
    117126                if( empty($this->wp_base) )
    … …  
    119128                return $this->wp_base;
    120129        }
     130
    121131        function get_contents($file,$type='',$resumepos=0){
    122132                if( empty($type) ){
    … …  
    125135                }
    126136                $this->ftp->SetType($type);
    127                
    128                 return $this->ftp->get($file);
    129         }
     137                $temp = tmpfile();
     138                if ( ! $this->ftp->fget($temp, $file) ) {
     139                        fclose($temp);
     140                        return false;
     141                }
     142                fseek($temp, 0); //Skip back to the start of the file being written to
     143                $contents = '';
     144                while ( !feof($temp) )
     145                        $contents .= fread($temp, 8192);
     146                fclose($temp);
     147                return $contents;
     148        }
     149
    130150        function get_contents_array($file){
    131151                return explode("\n",$this->get_contents($file));
    132152        }
     153
    133154        function put_contents($file,$contents,$type=''){
    134155                if( empty($type) ){
    135                         $extension = substr(strrchr($filename, "."), 1);
     156                        $extension = substr(strrchr($file, "."), 1);
    136157                        $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
    137158                }
    … …  
    141162                fwrite($temp,$contents);
    142163                fseek($temp, 0); //Skip back to the start of the file being written to
    143                 $ret = $this->ftp->put($temp, $file);
     164                $ret = $this->ftp->fput($file, $temp);
    144165                fclose($temp);
    145166                return $ret;
    146167        }
     168
    147169        function cwd(){
    148170                return $this->ftp->pwd();
    149171        }
     172
    150173        function chgrp($file,$group,$recursive=false){
    151174                return false;
    152175        }
     176       
    153177        function chmod($file,$mode=false,$recursive=false){
    154178                if( ! $mode )
    … …  
    168192                return true;
    169193        }
     194       
    170195        function chown($file,$owner,$recursive=false){
    171196                return false;
    172197        }
     198       
    173199        function owner($file){
    174200                $dir = $this->dirlist($file);
    175201                return $dir[$file]['owner'];
    176202        }
     203       
    177204        function getchmod($file){
    178205                $dir = $this->dirlist($file);
    179206                return $dir[$file]['permsn'];
    180207        }
     208
    181209        function gethchmod($file){
    182210                //From the PHP.net page for ...?
    … …  
    230258                return $info;
    231259        }
     260
    232261        function getnumchmodfromh($mode) {
    233262                $realmode = "";
    … …  
    248277                return $newmode;
    249278        }
     279
    250280        function group($file){
    251281                $dir = $this->dirlist($file);
    252282                return $dir[$file]['group'];
    253283        }
     284
    254285        function copy($source,$destination,$overwrite=false){
    255286                if( ! $overwrite && $this->exists($destination) )
    256287                        return false;
     288
    257289                $content = $this->get_contents($source);
    258                 $this->put_contents($destination,$content);
    259         }
     290                if ( !$content )
     291                        return false;
     292
     293                return $this->put_contents($destination,$content);
     294        }
     295
    260296        function move($source,$destination,$overwrite=false){
    261297                return $this->ftp->rename($source,$destination);
    … …  
    267303                if ( !$recursive )
    268304                        return $this->ftp->rmdir($file);
    269                 $filelist = $this->dirlist($file);
    270                 foreach ($filelist as $filename) {
    271                         $this->delete($file.'/'.$filename,$recursive);
    272                 }
    273                 return $this->ftp->rmdir($file);
     305
     306                return $this->ftp->mdel($file);
    274307        }
    275308
    … …  
    277310                return $this->ftp->is_exists($file);
    278311        }
     312
    279313        function is_file($file){
    280                 //return $this->ftp->file_exists($file);
    281                 $list = $this->ftp->rawlist($file,'-a');
    282                 if( ! $list )
    283                         return false;
    284                 return ($list[0] == '-');
    285         }
     314                return $this->is_dir($file) ? false : true;
     315        }
     316
    286317        function is_dir($path){
    287                 $list = $this->ftp->rawlist($file,'-a');
    288                 if( ! $list )
    289                         return false;
    290                 return true;
    291         }
     318                $cwd = $this->cwd();
     319                if ( $this->ftp->chdir($path) ) {
     320                        $this->ftp->chdir($cwd);
     321                        return true;
     322                }
     323                return false;
     324        }
     325
    292326        function is_readable($file){
    293327                //Get dir list, Check if the file is writable by the current user??
    294328                return true;
    295329        }
     330
    296331        function is_writable($file){
    297332                //Get dir list, Check if the file is writable by the current user??
    298333                return true;
    299334        }
     335
    300336        function atime($file){
    301337                return false;
    302338        }
     339
    303340        function mtime($file){
    304341                return $this->ftp->mdtm($file);
    305342        }
     343
    306344        function size($file){
    307345                return $this->ftp->filesize($file);
    308346        }
     347
    309348        function touch($file,$time=0,$atime=0){
    310349                return false;
    311350        }
     351
    312352        function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
    313353                if( ! $this->ftp->mkdir($path) )
    314354                        return false;
    315355                if( $chmod )
    316                         $this->chmod($chmod);
     356                        $this->chmod($path, $chmod);
    317357                if( $chown )
    318                         $this->chown($chown);
     358                        $this->chown($path, $chown);
    319359                if( $chgrp )
    320                         $this->chgrp($chgrp);
     360                        $this->chgrp($path, $chgrp);
    321361                return true;
    322362        }
     363
    323364        function rmdir($path,$recursive=false){
    324365                if( ! $recursive )
    325366                        return $this->ftp->rmdir($file);
    326                 return false;
    327                 //TODO: Recursive Directory delete, Have to delete files from the folder first.
    328                 //$dir = $this->dirlist($path);
    329                 //foreach($dir as $file)
    330                        
    331         }
     367
     368                return $this->ftp->mdel($path);
     369        }
     370
    332371        function dirlist($path='.',$incdot=false,$recursive=false){
    333372                if( $this->is_file($path) ){
    … …  
    339378                //if( ! $this->is_dir($path) )
    340379                //      return false;
    341                 $list = $this->ftp->rawlist($path,'-a');
    342                 //var_dump($list);
     380                $list = $this->ftp->dirlist($path);
    343381                if( ! $list )
    344382                        return false;
    … …  
    347385
    348386                $ret = array();
    349                 foreach($list as $line){
    350                         $struc = array();
    351                         $current = preg_split("/[\s]+/",$line,9);
    352                         $struc['name']          = str_replace('//','',$current[8]);
    353 
    354                         if( '.' == $struc['name'][0] && !$incdot)
    355                                 continue;
    356                         if( $limitFile && $struc['name'] != $limitFile)
    357                                 continue;
    358 
    359                         $struc['perms']         = $current[0];
    360                         $struc['permsn']        = $this->getnumchmodfromh($current[0]);
    361                         $struc['number']        = $current[1];
    362                         $struc['owner']         = $current[2];
    363                         $struc['group']         = $current[3];
    364                         $struc['size']          = $current[4];
    365                         $struc['lastmod']   = $current[5].' '.$current[6];
    366                         $struc['time']          = $current[7];
    367 
    368                         $struc['type']          = ('d' == $struc['perms'][0] || 'l' == $struc['perms'][0] ) ? 'folder' : 'file';
    369                         if('folder' == $struc['type'] ){
     387                foreach ( $list as $struc ) {
     388                       
     389                        if ( 'd' == $struc['type'] ) {
    370390                                $struc['files'] = array();
    371391
    372                                 if( $incdot ){
     392                                if ( $incdot ){
    373393                                        //We're including the doted starts
    374394                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    … …  
    386406                return $ret;
    387407        }
     408
    388409        function __destruct(){
    389410                $this->ftp->quit();
Note: See TracChangeset for help on using the changeset viewer.