[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-filesystem-ftpext.php (source)

   1  <?php
   2  /**
   3   * WordPress FTP Filesystem.
   4   *
   5   * @package WordPress
   6   * @subpackage Filesystem
   7   */
   8  
   9  /**
  10   * WordPress Filesystem Class for implementing FTP.
  11   *
  12   * @since 2.5.0
  13   *
  14   * @see WP_Filesystem_Base
  15   */
  16  class WP_Filesystem_FTPext extends WP_Filesystem_Base {
  17  
  18      /**
  19       * @since 2.5.0
  20       * @var resource
  21       */
  22      public $link;
  23  
  24      /**
  25       * Constructor.
  26       *
  27       * @since 2.5.0
  28       *
  29       * @param array $opt
  30       */
  31  	public function __construct( $opt = '' ) {
  32          $this->method = 'ftpext';
  33          $this->errors = new WP_Error();
  34  
  35          // Check if possible to use ftp functions.
  36          if ( ! extension_loaded( 'ftp' ) ) {
  37              $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) );
  38              return;
  39          }
  40  
  41          // This class uses the timeout on a per-connection basis, others use it on a per-action basis.
  42          if ( ! defined( 'FS_TIMEOUT' ) ) {
  43              define( 'FS_TIMEOUT', 240 );
  44          }
  45  
  46          if ( empty( $opt['port'] ) ) {
  47              $this->options['port'] = 21;
  48          } else {
  49              $this->options['port'] = $opt['port'];
  50          }
  51  
  52          if ( empty( $opt['hostname'] ) ) {
  53              $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) );
  54          } else {
  55              $this->options['hostname'] = $opt['hostname'];
  56          }
  57  
  58          // Check if the options provided are OK.
  59          if ( empty( $opt['username'] ) ) {
  60              $this->errors->add( 'empty_username', __( 'FTP username is required' ) );
  61          } else {
  62              $this->options['username'] = $opt['username'];
  63          }
  64  
  65          if ( empty( $opt['password'] ) ) {
  66              $this->errors->add( 'empty_password', __( 'FTP password is required' ) );
  67          } else {
  68              $this->options['password'] = $opt['password'];
  69          }
  70  
  71          $this->options['ssl'] = false;
  72          if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) {
  73              $this->options['ssl'] = true;
  74          }
  75      }
  76  
  77      /**
  78       * Connects filesystem.
  79       *
  80       * @since 2.5.0
  81       *
  82       * @return bool True on success, false on failure.
  83       */
  84  	public function connect() {
  85          if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
  86              $this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
  87          } else {
  88              $this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
  89          }
  90  
  91          if ( ! $this->link ) {
  92              $this->errors->add(
  93                  'connect',
  94                  sprintf(
  95                      /* translators: %s: hostname:port */
  96                      __( 'Failed to connect to FTP Server %s' ),
  97                      $this->options['hostname'] . ':' . $this->options['port']
  98                  )
  99              );
 100              return false;
 101          }
 102  
 103          if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) {
 104              $this->errors->add(
 105                  'auth',
 106                  sprintf(
 107                      /* translators: %s: Username. */
 108                      __( 'Username/Password incorrect for %s' ),
 109                      $this->options['username']
 110                  )
 111              );
 112              return false;
 113          }
 114  
 115          // Set the connection to use Passive FTP.
 116          ftp_pasv( $this->link, true );
 117          if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
 118              @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
 119          }
 120  
 121          return true;
 122      }
 123  
 124      /**
 125       * Reads entire file into a string.
 126       *
 127       * @since 2.5.0
 128       *
 129       * @param string $file Name of the file to read.
 130       * @return string|false Read data on success, false if no temporary file could be opened,
 131       *                      or if the file couldn't be retrieved.
 132       */
 133  	public function get_contents( $file ) {
 134          $tempfile = wp_tempnam( $file );
 135          $temp     = fopen( $tempfile, 'w+' );
 136  
 137          if ( ! $temp ) {
 138              unlink( $tempfile );
 139              return false;
 140          }
 141  
 142          if ( ! ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
 143              fclose( $temp );
 144              unlink( $tempfile );
 145              return false;
 146          }
 147  
 148          fseek( $temp, 0 ); // Skip back to the start of the file being written to.
 149          $contents = '';
 150  
 151          while ( ! feof( $temp ) ) {
 152              $contents .= fread( $temp, 8 * KB_IN_BYTES );
 153          }
 154  
 155          fclose( $temp );
 156          unlink( $tempfile );
 157          return $contents;
 158      }
 159  
 160      /**
 161       * Reads entire file into an array.
 162       *
 163       * @since 2.5.0
 164       *
 165       * @param string $file Path to the file.
 166       * @return array|false File contents in an array on success, false on failure.
 167       */
 168  	public function get_contents_array( $file ) {
 169          return explode( "\n", $this->get_contents( $file ) );
 170      }
 171  
 172      /**
 173       * Writes a string to a file.
 174       *
 175       * @since 2.5.0
 176       *
 177       * @param string    $file     Remote path to the file where to write the data.
 178       * @param string    $contents The data to write.
 179       * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
 180       *                            Default false.
 181       * @return bool True on success, false on failure.
 182       */
 183  	public function put_contents( $file, $contents, $mode = false ) {
 184          $tempfile = wp_tempnam( $file );
 185          $temp     = fopen( $tempfile, 'wb+' );
 186  
 187          if ( ! $temp ) {
 188              unlink( $tempfile );
 189              return false;
 190          }
 191  
 192          mbstring_binary_safe_encoding();
 193  
 194          $data_length   = strlen( $contents );
 195          $bytes_written = fwrite( $temp, $contents );
 196  
 197          reset_mbstring_encoding();
 198  
 199          if ( $data_length !== $bytes_written ) {
 200              fclose( $temp );
 201              unlink( $tempfile );
 202              return false;
 203          }
 204  
 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          unlink( $tempfile );
 211  
 212          $this->chmod( $file, $mode );
 213  
 214          return $ret;
 215      }
 216  
 217      /**
 218       * Gets the current working directory.
 219       *
 220       * @since 2.5.0
 221       *
 222       * @return string|false The current working directory on success, false on failure.
 223       */
 224  	public function cwd() {
 225          $cwd = ftp_pwd( $this->link );
 226          if ( $cwd ) {
 227              $cwd = trailingslashit( $cwd );
 228          }
 229          return $cwd;
 230      }
 231  
 232      /**
 233       * Changes current directory.
 234       *
 235       * @since 2.5.0
 236       *
 237       * @param string $dir The new current directory.
 238       * @return bool True on success, false on failure.
 239       */
 240  	public function chdir( $dir ) {
 241          return @ftp_chdir( $this->link, $dir );
 242      }
 243  
 244      /**
 245       * Changes filesystem permissions.
 246       *
 247       * @since 2.5.0
 248       *
 249       * @param string    $file      Path to the file.
 250       * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
 251       *                             0755 for directories. Default false.
 252       * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
 253       *                             Default false.
 254       * @return bool True on success, false on failure.
 255       */
 256  	public function chmod( $file, $mode = false, $recursive = false ) {
 257          if ( ! $mode ) {
 258              if ( $this->is_file( $file ) ) {
 259                  $mode = FS_CHMOD_FILE;
 260              } elseif ( $this->is_dir( $file ) ) {
 261                  $mode = FS_CHMOD_DIR;
 262              } else {
 263                  return false;
 264              }
 265          }
 266  
 267          // chmod any sub-objects if recursive.
 268          if ( $recursive && $this->is_dir( $file ) ) {
 269              $filelist = $this->dirlist( $file );
 270              foreach ( (array) $filelist as $filename => $filemeta ) {
 271                  $this->chmod( $file . '/' . $filename, $mode, $recursive );
 272              }
 273          }
 274  
 275          // chmod the file or directory.
 276          if ( ! function_exists( 'ftp_chmod' ) ) {
 277              return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
 278          }
 279          return (bool) ftp_chmod( $this->link, $mode, $file );
 280      }
 281  
 282      /**
 283       * Gets the file owner.
 284       *
 285       * @since 2.5.0
 286       *
 287       * @param string $file Path to the file.
 288       * @return string|false Username of the owner on success, false on failure.
 289       */
 290  	public function owner( $file ) {
 291          $dir = $this->dirlist( $file );
 292          return $dir[ $file ]['owner'];
 293      }
 294  
 295      /**
 296       * Gets the permissions of the specified file or filepath in their octal format.
 297       *
 298       * @since 2.5.0
 299       *
 300       * @param string $file Path to the file.
 301       * @return string Mode of the file (the last 3 digits).
 302       */
 303  	public function getchmod( $file ) {
 304          $dir = $this->dirlist( $file );
 305          return $dir[ $file ]['permsn'];
 306      }
 307  
 308      /**
 309       * Gets the file's group.
 310       *
 311       * @since 2.5.0
 312       *
 313       * @param string $file Path to the file.
 314       * @return string|false The group on success, false on failure.
 315       */
 316  	public function group( $file ) {
 317          $dir = $this->dirlist( $file );
 318          return $dir[ $file ]['group'];
 319      }
 320  
 321      /**
 322       * Copies a file.
 323       *
 324       * @since 2.5.0
 325       *
 326       * @param string    $source      Path to the source file.
 327       * @param string    $destination Path to the destination file.
 328       * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
 329       *                               Default false.
 330       * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
 331       *                               0755 for dirs. Default false.
 332       * @return bool True on success, false on failure.
 333       */
 334  	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
 335          if ( ! $overwrite && $this->exists( $destination ) ) {
 336              return false;
 337          }
 338          $content = $this->get_contents( $source );
 339          if ( false === $content ) {
 340              return false;
 341          }
 342          return $this->put_contents( $destination, $content, $mode );
 343      }
 344  
 345      /**
 346       * Moves a file.
 347       *
 348       * @since 2.5.0
 349       *
 350       * @param string $source      Path to the source file.
 351       * @param string $destination Path to the destination file.
 352       * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
 353       *                            Default false.
 354       * @return bool True on success, false on failure.
 355       */
 356  	public function move( $source, $destination, $overwrite = false ) {
 357          return ftp_rename( $this->link, $source, $destination );
 358      }
 359  
 360      /**
 361       * Deletes a file or directory.
 362       *
 363       * @since 2.5.0
 364       *
 365       * @param string       $file      Path to the file or directory.
 366       * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
 367       *                                Default false.
 368       * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
 369       *                                Default false.
 370       * @return bool True on success, false on failure.
 371       */
 372  	public function delete( $file, $recursive = false, $type = false ) {
 373          if ( empty( $file ) ) {
 374              return false;
 375          }
 376          if ( 'f' === $type || $this->is_file( $file ) ) {
 377              return ftp_delete( $this->link, $file );
 378          }
 379          if ( ! $recursive ) {
 380              return ftp_rmdir( $this->link, $file );
 381          }
 382  
 383          $filelist = $this->dirlist( trailingslashit( $file ) );
 384          if ( ! empty( $filelist ) ) {
 385              foreach ( $filelist as $delete_file ) {
 386                  $this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
 387              }
 388          }
 389          return ftp_rmdir( $this->link, $file );
 390      }
 391  
 392      /**
 393       * Checks if a file or directory exists.
 394       *
 395       * @since 2.5.0
 396       *
 397       * @param string $file Path to file or directory.
 398       * @return bool Whether $file exists or not.
 399       */
 400  	public function exists( $file ) {
 401          $list = ftp_nlist( $this->link, $file );
 402  
 403          if ( empty( $list ) && $this->is_dir( $file ) ) {
 404              return true; // File is an empty directory.
 405          }
 406  
 407          return ! empty( $list ); // Empty list = no file, so invert.
 408      }
 409  
 410      /**
 411       * Checks if resource is a file.
 412       *
 413       * @since 2.5.0
 414       *
 415       * @param string $file File path.
 416       * @return bool Whether $file is a file.
 417       */
 418  	public function is_file( $file ) {
 419          return $this->exists( $file ) && ! $this->is_dir( $file );
 420      }
 421  
 422      /**
 423       * Checks if resource is a directory.
 424       *
 425       * @since 2.5.0
 426       *
 427       * @param string $path Directory path.
 428       * @return bool Whether $path is a directory.
 429       */
 430  	public function is_dir( $path ) {
 431          $cwd    = $this->cwd();
 432          $result = @ftp_chdir( $this->link, trailingslashit( $path ) );
 433          if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
 434              @ftp_chdir( $this->link, $cwd );
 435              return true;
 436          }
 437          return false;
 438      }
 439  
 440      /**
 441       * Checks if a file is readable.
 442       *
 443       * @since 2.5.0
 444       *
 445       * @param string $file Path to file.
 446       * @return bool Whether $file is readable.
 447       */
 448  	public function is_readable( $file ) {
 449          return true;
 450      }
 451  
 452      /**
 453       * Checks if a file or directory is writable.
 454       *
 455       * @since 2.5.0
 456       *
 457       * @param string $file Path to file or directory.
 458       * @return bool Whether $file is writable.
 459       */
 460  	public function is_writable( $file ) {
 461          return true;
 462      }
 463  
 464      /**
 465       * Gets the file's last access time.
 466       *
 467       * @since 2.5.0
 468       *
 469       * @param string $file Path to file.
 470       * @return int|false Unix timestamp representing last access time, false on failure.
 471       */
 472  	public function atime( $file ) {
 473          return false;
 474      }
 475  
 476      /**
 477       * Gets the file modification time.
 478       *
 479       * @since 2.5.0
 480       *
 481       * @param string $file Path to file.
 482       * @return int|false Unix timestamp representing modification time, false on failure.
 483       */
 484  	public function mtime( $file ) {
 485          return ftp_mdtm( $this->link, $file );
 486      }
 487  
 488      /**
 489       * Gets the file size (in bytes).
 490       *
 491       * @since 2.5.0
 492       *
 493       * @param string $file Path to file.
 494       * @return int|false Size of the file in bytes on success, false on failure.
 495       */
 496  	public function size( $file ) {
 497          return ftp_size( $this->link, $file );
 498      }
 499  
 500      /**
 501       * Sets the access and modification times of a file.
 502       *
 503       * Note: If $file doesn't exist, it will be created.
 504       *
 505       * @since 2.5.0
 506       *
 507       * @param string $file  Path to file.
 508       * @param int    $time  Optional. Modified time to set for file.
 509       *                      Default 0.
 510       * @param int    $atime Optional. Access time to set for file.
 511       *                      Default 0.
 512       * @return bool True on success, false on failure.
 513       */
 514  	public function touch( $file, $time = 0, $atime = 0 ) {
 515          return false;
 516      }
 517  
 518      /**
 519       * Creates a directory.
 520       *
 521       * @since 2.5.0
 522       *
 523       * @param string     $path  Path for new directory.
 524       * @param int|false  $chmod Optional. The permissions as octal number (or false to skip chmod).
 525       *                          Default false.
 526       * @param string|int $chown Optional. A user name or number (or false to skip chown).
 527       *                          Default false.
 528       * @param string|int $chgrp Optional. A group name or number (or false to skip chgrp).
 529       *                          Default false.
 530       * @return bool True on success, false on failure.
 531       */
 532  	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
 533          $path = untrailingslashit( $path );
 534          if ( empty( $path ) ) {
 535              return false;
 536          }
 537  
 538          if ( ! ftp_mkdir( $this->link, $path ) ) {
 539              return false;
 540          }
 541          $this->chmod( $path, $chmod );
 542          return true;
 543      }
 544  
 545      /**
 546       * Deletes a directory.
 547       *
 548       * @since 2.5.0
 549       *
 550       * @param string $path      Path to directory.
 551       * @param bool   $recursive Optional. Whether to recursively remove files/directories.
 552       *                          Default false.
 553       * @return bool True on success, false on failure.
 554       */
 555  	public function rmdir( $path, $recursive = false ) {
 556          return $this->delete( $path, $recursive );
 557      }
 558  
 559      /**
 560       * @staticvar bool $is_windows
 561       * @param string $line
 562       * @return array
 563       */
 564  	public function parselisting( $line ) {
 565          static $is_windows = null;
 566          if ( is_null( $is_windows ) ) {
 567              $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
 568          }
 569  
 570          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              $b = array();
 572              if ( $lucifer[3] < 70 ) {
 573                  $lucifer[3] += 2000;
 574              } else {
 575                  $lucifer[3] += 1900; // 4-digit year fix.
 576              }
 577              $b['isdir'] = ( '<DIR>' === $lucifer[7] );
 578              if ( $b['isdir'] ) {
 579                  $b['type'] = 'd';
 580              } else {
 581                  $b['type'] = 'f';
 582              }
 583              $b['size']   = $lucifer[7];
 584              $b['month']  = $lucifer[1];
 585              $b['day']    = $lucifer[2];
 586              $b['year']   = $lucifer[3];
 587              $b['hour']   = $lucifer[4];
 588              $b['minute'] = $lucifer[5];
 589              $b['time']   = mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
 590              $b['am/pm']  = $lucifer[6];
 591              $b['name']   = $lucifer[8];
 592          } elseif ( ! $is_windows ) {
 593              $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY );
 594              if ( $lucifer ) {
 595                  // echo $line."\n";
 596                  $lcount = count( $lucifer );
 597                  if ( $lcount < 8 ) {
 598                      return '';
 599                  }
 600                  $b           = array();
 601                  $b['isdir']  = 'd' === $lucifer[0][0];
 602                  $b['islink'] = 'l' === $lucifer[0][0];
 603                  if ( $b['isdir'] ) {
 604                      $b['type'] = 'd';
 605                  } elseif ( $b['islink'] ) {
 606                      $b['type'] = 'l';
 607                  } else {
 608                      $b['type'] = 'f';
 609                  }
 610                  $b['perms']  = $lucifer[0];
 611                  $b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
 612                  $b['number'] = $lucifer[1];
 613                  $b['owner']  = $lucifer[2];
 614                  $b['group']  = $lucifer[3];
 615                  $b['size']   = $lucifer[4];
 616                  if ( 8 == $lcount ) {
 617                      sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
 618                      sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
 619                      $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
 620                      $b['name'] = $lucifer[7];
 621                  } else {
 622                      $b['month'] = $lucifer[5];
 623                      $b['day']   = $lucifer[6];
 624                      if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
 625                          $b['year']   = gmdate( 'Y' );
 626                          $b['hour']   = $l2[1];
 627                          $b['minute'] = $l2[2];
 628                      } else {
 629                          $b['year']   = $lucifer[7];
 630                          $b['hour']   = 0;
 631                          $b['minute'] = 0;
 632                      }
 633                      $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
 634                      $b['name'] = $lucifer[8];
 635                  }
 636              }
 637          }
 638  
 639          // Replace symlinks formatted as "source -> target" with just the source name.
 640          if ( isset( $b['islink'] ) && $b['islink'] ) {
 641              $b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
 642          }
 643  
 644          return $b;
 645      }
 646  
 647      /**
 648       * Gets details for files in a directory or a specific file.
 649       *
 650       * @since 2.5.0
 651       *
 652       * @param string $path           Path to directory or file.
 653       * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
 654       *                               Default true.
 655       * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
 656       *                               Default false.
 657       * @return array|false {
 658       *     Array of files. False if unable to list directory contents.
 659       *
 660       *     @type string $name        Name of the file or directory.
 661       *     @type string $perms       *nix representation of permissions.
 662       *     @type int    $permsn      Octal representation of permissions.
 663       *     @type string $owner       Owner name or ID.
 664       *     @type int    $size        Size of file in bytes.
 665       *     @type int    $lastmodunix Last modified unix timestamp.
 666       *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
 667       *     @type int    $time        Last modified time.
 668       *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
 669       *     @type mixed  $files       If a directory and $recursive is true, contains another array of files.
 670       * }
 671       */
 672  	public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
 673          if ( $this->is_file( $path ) ) {
 674              $limit_file = basename( $path );
 675              $path       = dirname( $path ) . '/';
 676          } else {
 677              $limit_file = false;
 678          }
 679  
 680          $pwd = ftp_pwd( $this->link );
 681          if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
 682              return false;
 683          }
 684          $list = ftp_rawlist( $this->link, '-a', false );
 685          @ftp_chdir( $this->link, $pwd );
 686  
 687          if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least).
 688              return false;
 689          }
 690  
 691          $dirlist = array();
 692          foreach ( $list as $k => $v ) {
 693              $entry = $this->parselisting( $v );
 694              if ( empty( $entry ) ) {
 695                  continue;
 696              }
 697  
 698              if ( '.' === $entry['name'] || '..' === $entry['name'] ) {
 699                  continue;
 700              }
 701  
 702              if ( ! $include_hidden && '.' === $entry['name'][0] ) {
 703                  continue;
 704              }
 705  
 706              if ( $limit_file && $entry['name'] != $limit_file ) {
 707                  continue;
 708              }
 709  
 710              $dirlist[ $entry['name'] ] = $entry;
 711          }
 712  
 713          $ret = array();
 714          foreach ( (array) $dirlist as $struc ) {
 715              if ( 'd' === $struc['type'] ) {
 716                  if ( $recursive ) {
 717                      $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
 718                  } else {
 719                      $struc['files'] = array();
 720                  }
 721              }
 722  
 723              $ret[ $struc['name'] ] = $struc;
 724          }
 725          return $ret;
 726      }
 727  
 728      /**
 729       * Destructor.
 730       *
 731       * @since 2.5.0
 732       */
 733  	public function __destruct() {
 734          if ( $this->link ) {
 735              ftp_close( $this->link );
 736          }
 737      }
 738  }


Generated: Fri May 29 01:00:08 2020 Cross-referenced by PHPXref 0.7.1