Changeset 7126 for trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
- Timestamp:
- 03/01/2008 09:20:23 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r7063 r7126 167 167 if( ! $mode ) 168 168 return false; 169 if ( ! $this->exists($file) )170 return false; 171 if ( ! $recursive || ! $this->is_dir($file) ){169 if ( ! $this->exists($file) ) 170 return false; 171 if ( ! $recursive || ! $this->is_dir($file) ){ 172 172 if (!function_exists('ftp_chmod')) 173 173 return ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); … … 268 268 if( ! $overwrite && $this->exists($destination) ) 269 269 return false; 270 $content = $this->get_contents($source); 271 $this->put_contents($destination,$content); 270 if ( !$content = $this->get_contents($source) ) 271 return false; 272 return $this->put_contents($destination,$content); 272 273 } 273 274 function move($source,$destination,$overwrite=false){ … … 281 282 return @ftp_rmdir($this->link,$file); 282 283 $filelist = $this->dirlist($file); 283 foreach ( $filelist as $filename => $fileinfo) {284 foreach ((array) $filelist as $filename => $fileinfo) { 284 285 $this->delete($file.'/'.$filename,$recursive); 285 286 } … … 328 329 return false; 329 330 if( $chmod ) 330 $this->chmod($ chmod);331 $this->chmod($path, $chmod); 331 332 if( $chown ) 332 $this->chown($ chown);333 $this->chown($path, $chown); 333 334 if( $chgrp ) 334 $this->chgrp($ chgrp);335 $this->chgrp($path, $chgrp); 335 336 return true; 336 337 } … … 344 345 345 346 } 347 348 function parselisting($line) { 349 $is_windows = ($this->OS_remote == FTP_OS_Windows); 350 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)) { 351 $b = array(); 352 if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix 353 $b['isdir'] = ($lucifer[7]=="<DIR>"); 354 if ( $b['isdir'] ) 355 $b['type'] = 'd'; 356 else 357 $b['type'] = 'f'; 358 $b['size'] = $lucifer[7]; 359 $b['month'] = $lucifer[1]; 360 $b['day'] = $lucifer[2]; 361 $b['year'] = $lucifer[3]; 362 $b['hour'] = $lucifer[4]; 363 $b['minute'] = $lucifer[5]; 364 $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]); 365 $b['am/pm'] = $lucifer[6]; 366 $b['name'] = $lucifer[8]; 367 } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) { 368 //echo $line."\n"; 369 $lcount=count($lucifer); 370 if ($lcount<8) return ''; 371 $b = array(); 372 $b['isdir'] = $lucifer[0]{0} === "d"; 373 $b['islink'] = $lucifer[0]{0} === "l"; 374 if ( $b['isdir'] ) 375 $b['type'] = 'd'; 376 elseif ( $b['islink'] ) 377 $b['type'] = 'l'; 378 else 379 $b['type'] = 'f'; 380 $b['perms'] = $lucifer[0]; 381 $b['number'] = $lucifer[1]; 382 $b['owner'] = $lucifer[2]; 383 $b['group'] = $lucifer[3]; 384 $b['size'] = $lucifer[4]; 385 if ($lcount==8) { 386 sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']); 387 sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']); 388 $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']); 389 $b['name'] = $lucifer[7]; 390 } else { 391 $b['month'] = $lucifer[5]; 392 $b['day'] = $lucifer[6]; 393 if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) { 394 $b['year'] = date("Y"); 395 $b['hour'] = $l2[1]; 396 $b['minute'] = $l2[2]; 397 } else { 398 $b['year'] = $lucifer[7]; 399 $b['hour'] = 0; 400 $b['minute'] = 0; 401 } 402 $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute'])); 403 $b['name'] = $lucifer[8]; 404 } 405 } 406 407 return $b; 408 } 409 346 410 function dirlist($path='.',$incdot=false,$recursive=false){ 347 411 if( $this->is_file($path) ){ … … 353 417 //if( ! $this->is_dir($path) ) 354 418 // return false; 355 $list = ftp_rawlist($this->link,$path,false); //We'll do the recursive part ourseves... 356 //var_dump($list); 357 if( ! $list ) 358 return false; 359 if( empty($list) ) 419 $list = ftp_rawlist($this->link , '-a ' . $path, false); 420 if ( $list === false ) 421 return false; 422 423 $dirlist = array(); 424 foreach ( $list as $k => $v ) { 425 $entry = $this->parselisting($v); 426 if ( empty($entry) ) 427 continue; 428 429 if ( $entry["name"]=="." or $entry["name"]==".." ) 430 continue; 431 432 $dirlist[$entry['name']] = $entry; 433 } 434 435 if ( ! $dirlist ) 436 return false; 437 if ( empty($dirlist) ) 360 438 return array(); 361 439 362 440 $ret = array(); 363 foreach($list as $line){ 364 if (substr(strtolower($line), 0, 5) == 'total') continue; 365 $struc = array(); 366 $current = preg_split("/[\s]+/",$line,9); 367 $name_num = count($current) - 1; 368 $struc['name'] = str_replace('//','',$current[$name_num]); 369 370 if( '.' == $struc['name'][0] && !$incdot) 371 continue; 372 if( $limitFile && $struc['name'] != $limitFile) 373 continue; 374 375 $struc['perms'] = $current[0]; 376 $struc['permsn'] = $this->getnumchmodfromh($current[0]); 377 $struc['number'] = $current[1]; 378 $struc['owner'] = $current[2]; 379 $struc['group'] = $current[3]; 380 $struc['size'] = $current[4]; 381 $struc['lastmod'] = $current[5].' '.$current[6]; 382 $struc['time'] = $current[7]; 383 384 $struc['type'] = ('d' == $struc['perms'][0] || 'l' == $struc['perms'][0] ) ? 'folder' : 'file'; 385 if('folder' == $struc['type'] ){ 441 foreach ( $dirlist as $struc ) { 442 443 if ( 'd' == $struc['type'] ) { 386 444 $struc['files'] = array(); 387 445 388 if ( $incdot ){446 if ( $incdot ){ 389 447 //We're including the doted starts 390 448 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder … … 402 460 return $ret; 403 461 } 462 404 463 function __destruct(){ 405 464 if( $this->link )
Note: See TracChangeset
for help on using the changeset viewer.