- Timestamp:
- 06/19/2020 10:34:26 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php
r47808 r48089 70 70 71 71 $this->options['ssl'] = false; 72 72 73 if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { 73 74 $this->options['ssl'] = true; … … 98 99 ) 99 100 ); 101 100 102 return false; 101 103 } … … 110 112 ) 111 113 ); 114 112 115 return false; 113 116 } … … 115 118 // Set the connection to use Passive FTP. 116 119 ftp_pasv( $this->link, true ); 120 117 121 if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) { 118 122 @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT ); … … 132 136 */ 133 137 public function get_contents( $file ) { 134 $tempfile = wp_tempnam( $file );135 $temp 136 137 if ( ! $temp ) {138 $tempfile = wp_tempnam( $file ); 139 $temphandle = fopen( $tempfile, 'w+' ); 140 141 if ( ! $temphandle ) { 138 142 unlink( $tempfile ); 139 143 return false; 140 144 } 141 145 142 if ( ! ftp_fget( $this->link, $temp , $file, FTP_BINARY ) ) {143 fclose( $temp );146 if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) { 147 fclose( $temphandle ); 144 148 unlink( $tempfile ); 145 149 return false; 146 150 } 147 151 148 fseek( $temp , 0 ); // Skip back to the start of the file being written to.152 fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. 149 153 $contents = ''; 150 154 151 while ( ! feof( $temp ) ) {152 $contents .= fread( $temp , 8 * KB_IN_BYTES );153 } 154 155 fclose( $temp );155 while ( ! feof( $temphandle ) ) { 156 $contents .= fread( $temphandle, 8 * KB_IN_BYTES ); 157 } 158 159 fclose( $temphangle ); 156 160 unlink( $tempfile ); 161 157 162 return $contents; 158 163 } … … 182 187 */ 183 188 public function put_contents( $file, $contents, $mode = false ) { 184 $tempfile = wp_tempnam( $file );185 $temp 186 187 if ( ! $temp ) {189 $tempfile = wp_tempnam( $file ); 190 $temphandle = fopen( $tempfile, 'wb+' ); 191 192 if ( ! $temphandle ) { 188 193 unlink( $tempfile ); 189 194 return false; … … 193 198 194 199 $data_length = strlen( $contents ); 195 $bytes_written = fwrite( $temp , $contents );200 $bytes_written = fwrite( $temphandle, $contents ); 196 201 197 202 reset_mbstring_encoding(); 198 203 199 204 if ( $data_length !== $bytes_written ) { 200 fclose( $temp );205 fclose( $temphandle ); 201 206 unlink( $tempfile ); 202 207 return false; 203 208 } 204 209 205 fseek( $temp , 0 ); // Skip back to the start of the file being written to.206 207 $ret = ftp_fput( $this->link, $file, $temp , FTP_BINARY );208 209 fclose( $temp );210 fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. 211 212 $ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY ); 213 214 fclose( $temphandle ); 210 215 unlink( $tempfile ); 211 216 … … 224 229 public function cwd() { 225 230 $cwd = ftp_pwd( $this->link ); 231 226 232 if ( $cwd ) { 227 233 $cwd = trailingslashit( $cwd ); 228 234 } 235 229 236 return $cwd; 230 237 } … … 268 275 if ( $recursive && $this->is_dir( $file ) ) { 269 276 $filelist = $this->dirlist( $file ); 277 270 278 foreach ( (array) $filelist as $filename => $filemeta ) { 271 279 $this->chmod( $file . '/' . $filename, $mode, $recursive ); … … 277 285 return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) ); 278 286 } 287 279 288 return (bool) ftp_chmod( $this->link, $mode, $file ); 280 289 } … … 290 299 public function owner( $file ) { 291 300 $dir = $this->dirlist( $file ); 301 292 302 return $dir[ $file ]['owner']; 293 303 } … … 303 313 public function getchmod( $file ) { 304 314 $dir = $this->dirlist( $file ); 315 305 316 return $dir[ $file ]['permsn']; 306 317 } … … 316 327 public function group( $file ) { 317 328 $dir = $this->dirlist( $file ); 329 318 330 return $dir[ $file ]['group']; 319 331 } … … 336 348 return false; 337 349 } 350 338 351 $content = $this->get_contents( $source ); 352 339 353 if ( false === $content ) { 340 354 return false; 341 355 } 356 342 357 return $this->put_contents( $destination, $content, $mode ); 343 358 } … … 374 389 return false; 375 390 } 391 376 392 if ( 'f' === $type || $this->is_file( $file ) ) { 377 393 return ftp_delete( $this->link, $file ); 378 394 } 395 379 396 if ( ! $recursive ) { 380 397 return ftp_rmdir( $this->link, $file ); … … 382 399 383 400 $filelist = $this->dirlist( trailingslashit( $file ) ); 401 384 402 if ( ! empty( $filelist ) ) { 385 403 foreach ( $filelist as $delete_file ) { … … 387 405 } 388 406 } 407 389 408 return ftp_rmdir( $this->link, $file ); 390 409 } … … 431 450 $cwd = $this->cwd(); 432 451 $result = @ftp_chdir( $this->link, trailingslashit( $path ) ); 452 433 453 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 434 454 @ftp_chdir( $this->link, $cwd ); 435 455 return true; 436 456 } 457 437 458 return false; 438 459 } … … 532 553 public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { 533 554 $path = untrailingslashit( $path ); 555 534 556 if ( empty( $path ) ) { 535 557 return false; … … 539 561 return false; 540 562 } 563 541 564 $this->chmod( $path, $chmod ); 565 542 566 return true; 543 567 } … … 564 588 public function parselisting( $line ) { 565 589 static $is_windows = null; 590 566 591 if ( is_null( $is_windows ) ) { 567 592 $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false; … … 570 595 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 ) ) { 571 596 $b = array(); 597 572 598 if ( $lucifer[3] < 70 ) { 573 599 $lucifer[3] += 2000; … … 575 601 $lucifer[3] += 1900; // 4-digit year fix. 576 602 } 603 577 604 $b['isdir'] = ( '<DIR>' === $lucifer[7] ); 605 578 606 if ( $b['isdir'] ) { 579 607 $b['type'] = 'd'; … … 581 609 $b['type'] = 'f'; 582 610 } 611 583 612 $b['size'] = $lucifer[7]; 584 613 $b['month'] = $lucifer[1]; … … 592 621 } elseif ( ! $is_windows ) { 593 622 $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ); 623 594 624 if ( $lucifer ) { 595 625 // echo $line."\n"; 596 626 $lcount = count( $lucifer ); 627 597 628 if ( $lcount < 8 ) { 598 629 return ''; 599 630 } 631 600 632 $b = array(); 601 633 $b['isdir'] = 'd' === $lucifer[0][0]; 602 634 $b['islink'] = 'l' === $lucifer[0][0]; 635 603 636 if ( $b['isdir'] ) { 604 637 $b['type'] = 'd'; … … 608 641 $b['type'] = 'f'; 609 642 } 643 610 644 $b['perms'] = $lucifer[0]; 611 645 $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); … … 614 648 $b['group'] = $lucifer[3]; 615 649 $b['size'] = $lucifer[4]; 650 616 651 if ( 8 == $lcount ) { 617 652 sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); 618 653 sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); 654 619 655 $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); 620 656 $b['name'] = $lucifer[7]; … … 622 658 $b['month'] = $lucifer[5]; 623 659 $b['day'] = $lucifer[6]; 660 624 661 if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { 625 662 $b['year'] = gmdate( 'Y' ); … … 631 668 $b['minute'] = 0; 632 669 } 670 633 671 $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); 634 672 $b['name'] = $lucifer[8]; … … 679 717 680 718 $pwd = ftp_pwd( $this->link ); 719 681 720 if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist. 682 721 return false; 683 722 } 723 684 724 $list = ftp_rawlist( $this->link, '-a', false ); 725 685 726 @ftp_chdir( $this->link, $pwd ); 686 727 … … 690 731 691 732 $dirlist = array(); 733 692 734 foreach ( $list as $k => $v ) { 693 735 $entry = $this->parselisting( $v ); 736 694 737 if ( empty( $entry ) ) { 695 738 continue; … … 712 755 713 756 $ret = array(); 757 714 758 foreach ( (array) $dirlist as $struc ) { 715 759 if ( 'd' === $struc['type'] ) { … … 723 767 $ret[ $struc['name'] ] = $struc; 724 768 } 769 725 770 return $ret; 726 771 }
Note: See TracChangeset
for help on using the changeset viewer.