- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php
r41161 r42343 18 18 19 19 /** 20 *21 20 * @param array $opt 22 21 */ … … 26 25 27 26 // Check if possible to use ftp functions. 28 if ( ! extension_loaded( 'ftp') ) {29 $this->errors->add( 'no_ftp_ext', __('The ftp PHP extension is not available'));27 if ( ! extension_loaded( 'ftp' ) ) { 28 $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) ); 30 29 return; 31 30 } … … 33 32 // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis. 34 33 35 if ( ! defined('FS_TIMEOUT') ) 36 define('FS_TIMEOUT', 240); 37 38 if ( empty($opt['port']) ) 34 if ( ! defined( 'FS_TIMEOUT' ) ) { 35 define( 'FS_TIMEOUT', 240 ); 36 } 37 38 if ( empty( $opt['port'] ) ) { 39 39 $this->options['port'] = 21; 40 else40 } else { 41 41 $this->options['port'] = $opt['port']; 42 43 if ( empty($opt['hostname']) ) 44 $this->errors->add('empty_hostname', __('FTP hostname is required')); 45 else 42 } 43 44 if ( empty( $opt['hostname'] ) ) { 45 $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) ); 46 } else { 46 47 $this->options['hostname'] = $opt['hostname']; 48 } 47 49 48 50 // Check if the options provided are OK. 49 if ( empty( $opt['username']) )50 $this->errors->add( 'empty_username', __('FTP username is required'));51 else51 if ( empty( $opt['username'] ) ) { 52 $this->errors->add( 'empty_username', __( 'FTP username is required' ) ); 53 } else { 52 54 $this->options['username'] = $opt['username']; 53 54 if ( empty($opt['password']) ) 55 $this->errors->add('empty_password', __('FTP password is required')); 56 else 55 } 56 57 if ( empty( $opt['password'] ) ) { 58 $this->errors->add( 'empty_password', __( 'FTP password is required' ) ); 59 } else { 57 60 $this->options['password'] = $opt['password']; 61 } 58 62 59 63 $this->options['ssl'] = false; 60 if ( isset( $opt['connection_type']) && 'ftps' == $opt['connection_type'] )64 if ( isset( $opt['connection_type'] ) && 'ftps' == $opt['connection_type'] ) { 61 65 $this->options['ssl'] = true; 62 }63 64 /** 65 66 } 67 } 68 69 /** 66 70 * @return bool 67 71 */ 68 72 public function connect() { 69 if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') ) 70 $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); 71 else 72 $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); 73 if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) { 74 $this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT ); 75 } else { 76 $this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT ); 77 } 73 78 74 79 if ( ! $this->link ) { 75 $this->errors->add( 'connect', 80 $this->errors->add( 81 'connect', 76 82 /* translators: %s: hostname:port */ 77 sprintf( __( 'Failed to connect to FTP Server %s' ), 83 sprintf( 84 __( 'Failed to connect to FTP Server %s' ), 78 85 $this->options['hostname'] . ':' . $this->options['port'] 79 86 ) … … 82 89 } 83 90 84 if ( ! @ftp_login( $this->link,$this->options['username'], $this->options['password'] ) ) { 85 $this->errors->add( 'auth', 91 if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) { 92 $this->errors->add( 93 'auth', 86 94 /* translators: %s: username */ 87 sprintf( __( 'Username/Password incorrect for %s' ), 95 sprintf( 96 __( 'Username/Password incorrect for %s' ), 88 97 $this->options['username'] 89 98 ) … … 94 103 // Set the Connection to use Passive FTP 95 104 @ftp_pasv( $this->link, true ); 96 if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT ) 97 @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT); 105 if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) { 106 @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT ); 107 } 98 108 99 109 return true; … … 110 120 */ 111 121 public function get_contents( $file ) { 112 $tempfile = wp_tempnam( $file);113 $temp = fopen($tempfile, 'w+');122 $tempfile = wp_tempnam( $file ); 123 $temp = fopen( $tempfile, 'w+' ); 114 124 115 125 if ( ! $temp ) { … … 127 137 $contents = ''; 128 138 129 while ( ! feof($temp) ) 130 $contents .= fread($temp, 8192); 131 132 fclose($temp); 133 unlink($tempfile); 139 while ( ! feof( $temp ) ) { 140 $contents .= fread( $temp, 8192 ); 141 } 142 143 fclose( $temp ); 144 unlink( $tempfile ); 134 145 return $contents; 135 146 } 136 147 137 148 /** 138 *139 149 * @param string $file 140 150 * @return array 141 151 */ 142 public function get_contents_array($file) { 143 return explode("\n", $this->get_contents($file)); 144 } 145 146 /** 147 * 152 public function get_contents_array( $file ) { 153 return explode( "\n", $this->get_contents( $file ) ); 154 } 155 156 /** 148 157 * @param string $file 149 158 * @param string $contents … … 151 160 * @return bool 152 161 */ 153 public function put_contents( $file, $contents, $mode = false ) {154 $tempfile = wp_tempnam( $file);155 $temp = fopen( $tempfile, 'wb+' );162 public function put_contents( $file, $contents, $mode = false ) { 163 $tempfile = wp_tempnam( $file ); 164 $temp = fopen( $tempfile, 'wb+' ); 156 165 157 166 if ( ! $temp ) { … … 162 171 mbstring_binary_safe_encoding(); 163 172 164 $data_length = strlen( $contents );173 $data_length = strlen( $contents ); 165 174 $bytes_written = fwrite( $temp, $contents ); 166 175 … … 177 186 $ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY ); 178 187 179 fclose( $temp);180 unlink( $tempfile);181 182 $this->chmod( $file, $mode);188 fclose( $temp ); 189 unlink( $tempfile ); 190 191 $this->chmod( $file, $mode ); 183 192 184 193 return $ret; … … 186 195 187 196 /** 188 *189 197 * @return string 190 198 */ 191 199 public function cwd() { 192 $cwd = @ftp_pwd($this->link); 193 if ( $cwd ) 194 $cwd = trailingslashit($cwd); 200 $cwd = @ftp_pwd( $this->link ); 201 if ( $cwd ) { 202 $cwd = trailingslashit( $cwd ); 203 } 195 204 return $cwd; 196 205 } 197 206 198 207 /** 199 *200 208 * @param string $dir 201 209 * @return bool 202 210 */ 203 public function chdir($dir) { 204 return @ftp_chdir($this->link, $dir); 205 } 206 207 /** 208 * 211 public function chdir( $dir ) { 212 return @ftp_chdir( $this->link, $dir ); 213 } 214 215 /** 209 216 * @param string $file 210 217 * @param int $mode … … 212 219 * @return bool 213 220 */ 214 public function chmod( $file, $mode = false, $recursive = false) {221 public function chmod( $file, $mode = false, $recursive = false ) { 215 222 if ( ! $mode ) { 216 if ( $this->is_file( $file) )223 if ( $this->is_file( $file ) ) { 217 224 $mode = FS_CHMOD_FILE; 218 elseif ( $this->is_dir($file) )225 } elseif ( $this->is_dir( $file ) ) { 219 226 $mode = FS_CHMOD_DIR; 220 else227 } else { 221 228 return false; 229 } 222 230 } 223 231 224 232 // chmod any sub-objects if recursive. 225 if ( $recursive && $this->is_dir($file) ) { 226 $filelist = $this->dirlist($file); 227 foreach ( (array)$filelist as $filename => $filemeta ) 228 $this->chmod($file . '/' . $filename, $mode, $recursive); 233 if ( $recursive && $this->is_dir( $file ) ) { 234 $filelist = $this->dirlist( $file ); 235 foreach ( (array) $filelist as $filename => $filemeta ) { 236 $this->chmod( $file . '/' . $filename, $mode, $recursive ); 237 } 229 238 } 230 239 231 240 // chmod the file or directory 232 if ( ! function_exists( 'ftp_chmod') )233 return (bool) @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));234 return (bool)@ftp_chmod($this->link, $mode, $file);235 }236 237 /** 238 241 if ( ! function_exists( 'ftp_chmod' ) ) { 242 return (bool) @ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) ); 243 } 244 return (bool) @ftp_chmod( $this->link, $mode, $file ); 245 } 246 247 /** 239 248 * @param string $file 240 249 * @return string 241 250 */ 242 public function owner($file) { 243 $dir = $this->dirlist($file); 244 return $dir[$file]['owner']; 245 } 246 /** 247 * 251 public function owner( $file ) { 252 $dir = $this->dirlist( $file ); 253 return $dir[ $file ]['owner']; 254 } 255 /** 248 256 * @param string $file 249 257 * @return string 250 258 */ 251 public function getchmod($file) { 252 $dir = $this->dirlist($file); 253 return $dir[$file]['permsn']; 254 } 255 256 /** 257 * 259 public function getchmod( $file ) { 260 $dir = $this->dirlist( $file ); 261 return $dir[ $file ]['permsn']; 262 } 263 264 /** 258 265 * @param string $file 259 266 * @return string 260 267 */ 261 public function group($file) { 262 $dir = $this->dirlist($file); 263 return $dir[$file]['group']; 264 } 265 266 /** 267 * 268 public function group( $file ) { 269 $dir = $this->dirlist( $file ); 270 return $dir[ $file ]['group']; 271 } 272 273 /** 268 274 * @param string $source 269 275 * @param string $destination … … 272 278 * @return bool 273 279 */ 274 public function copy($source, $destination, $overwrite = false, $mode = false) { 275 if ( ! $overwrite && $this->exists($destination) ) 276 return false; 277 $content = $this->get_contents($source); 278 if ( false === $content ) 279 return false; 280 return $this->put_contents($destination, $content, $mode); 281 } 282 283 /** 284 * 280 public function copy( $source, $destination, $overwrite = false, $mode = false ) { 281 if ( ! $overwrite && $this->exists( $destination ) ) { 282 return false; 283 } 284 $content = $this->get_contents( $source ); 285 if ( false === $content ) { 286 return false; 287 } 288 return $this->put_contents( $destination, $content, $mode ); 289 } 290 291 /** 285 292 * @param string $source 286 293 * @param string $destination … … 288 295 * @return bool 289 296 */ 290 public function move($source, $destination, $overwrite = false) { 291 return ftp_rename($this->link, $source, $destination); 292 } 293 294 /** 295 * 297 public function move( $source, $destination, $overwrite = false ) { 298 return ftp_rename( $this->link, $source, $destination ); 299 } 300 301 /** 296 302 * @param string $file 297 303 * @param bool $recursive … … 299 305 * @return bool 300 306 */ 301 public function delete($file, $recursive = false, $type = false) { 302 if ( empty($file) ) 303 return false; 304 if ( 'f' == $type || $this->is_file($file) ) 305 return @ftp_delete($this->link, $file); 306 if ( !$recursive ) 307 return @ftp_rmdir($this->link, $file); 308 309 $filelist = $this->dirlist( trailingslashit($file) ); 310 if ( !empty($filelist) ) 311 foreach ( $filelist as $delete_file ) 312 $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] ); 313 return @ftp_rmdir($this->link, $file); 314 } 315 316 /** 317 * 318 * @param string $file 319 * @return bool 320 */ 321 public function exists($file) { 322 $list = @ftp_nlist($this->link, $file); 307 public function delete( $file, $recursive = false, $type = false ) { 308 if ( empty( $file ) ) { 309 return false; 310 } 311 if ( 'f' == $type || $this->is_file( $file ) ) { 312 return @ftp_delete( $this->link, $file ); 313 } 314 if ( ! $recursive ) { 315 return @ftp_rmdir( $this->link, $file ); 316 } 317 318 $filelist = $this->dirlist( trailingslashit( $file ) ); 319 if ( ! empty( $filelist ) ) { 320 foreach ( $filelist as $delete_file ) { 321 $this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] ); 322 } 323 } 324 return @ftp_rmdir( $this->link, $file ); 325 } 326 327 /** 328 * @param string $file 329 * @return bool 330 */ 331 public function exists( $file ) { 332 $list = @ftp_nlist( $this->link, $file ); 323 333 324 334 if ( empty( $list ) && $this->is_dir( $file ) ) { … … 326 336 } 327 337 328 return !empty($list); //empty list = no file, so invert. 329 } 330 331 /** 332 * 333 * @param string $file 334 * @return bool 335 */ 336 public function is_file($file) { 337 return $this->exists($file) && !$this->is_dir($file); 338 } 339 340 /** 341 * 338 return ! empty( $list ); //empty list = no file, so invert. 339 } 340 341 /** 342 * @param string $file 343 * @return bool 344 */ 345 public function is_file( $file ) { 346 return $this->exists( $file ) && ! $this->is_dir( $file ); 347 } 348 349 /** 342 350 * @param string $path 343 351 * @return bool 344 352 */ 345 public function is_dir( $path) {346 $cwd = $this->cwd();347 $result = @ftp_chdir( $this->link, trailingslashit($path) );353 public function is_dir( $path ) { 354 $cwd = $this->cwd(); 355 $result = @ftp_chdir( $this->link, trailingslashit( $path ) ); 348 356 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 349 @ftp_chdir( $this->link, $cwd);357 @ftp_chdir( $this->link, $cwd ); 350 358 return true; 351 359 } … … 354 362 355 363 /** 356 * 357 * @param string $file 358 * @return bool 359 */ 360 public function is_readable($file) { 364 * @param string $file 365 * @return bool 366 */ 367 public function is_readable( $file ) { 361 368 return true; 362 369 } 363 370 364 371 /** 365 * 366 * @param string $file 367 * @return bool 368 */ 369 public function is_writable($file) { 372 * @param string $file 373 * @return bool 374 */ 375 public function is_writable( $file ) { 370 376 return true; 371 377 } 372 378 373 379 /** 374 * 375 * @param string $file 376 * @return bool 377 */ 378 public function atime($file) { 380 * @param string $file 381 * @return bool 382 */ 383 public function atime( $file ) { 379 384 return false; 380 385 } 381 386 382 387 /** 383 *384 388 * @param string $file 385 389 * @return int 386 390 */ 387 public function mtime($file) { 388 return ftp_mdtm($this->link, $file); 389 } 390 391 /** 392 * 391 public function mtime( $file ) { 392 return ftp_mdtm( $this->link, $file ); 393 } 394 395 /** 393 396 * @param string $file 394 397 * @return int 395 398 */ 396 public function size($file) { 397 return ftp_size($this->link, $file); 398 } 399 400 /** 401 * 402 * @param string $file 403 * @return bool 404 */ 405 public function touch($file, $time = 0, $atime = 0) { 399 public function size( $file ) { 400 return ftp_size( $this->link, $file ); 401 } 402 403 /** 404 * @param string $file 405 * @return bool 406 */ 407 public function touch( $file, $time = 0, $atime = 0 ) { 406 408 return false; 407 409 } 408 410 409 411 /** 410 *411 412 * @param string $path 412 413 * @param mixed $chmod … … 415 416 * @return bool 416 417 */ 417 public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 418 $path = untrailingslashit($path); 419 if ( empty($path) ) 420 return false; 421 422 if ( !@ftp_mkdir($this->link, $path) ) 423 return false; 424 $this->chmod($path, $chmod); 418 public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { 419 $path = untrailingslashit( $path ); 420 if ( empty( $path ) ) { 421 return false; 422 } 423 424 if ( ! @ftp_mkdir( $this->link, $path ) ) { 425 return false; 426 } 427 $this->chmod( $path, $chmod ); 425 428 return true; 426 429 } 427 430 428 431 /** 429 *430 432 * @param string $path 431 433 * @param bool $recursive 432 434 * @return bool 433 435 */ 434 public function rmdir($path, $recursive = false) { 435 return $this->delete($path, $recursive); 436 } 437 438 /** 439 * 436 public function rmdir( $path, $recursive = false ) { 437 return $this->delete( $path, $recursive ); 438 } 439 440 /** 440 441 * @staticvar bool $is_windows 441 442 * @param string $line 442 443 * @return array 443 444 */ 444 public function parselisting( $line) {445 public function parselisting( $line ) { 445 446 static $is_windows = null; 446 if ( is_null($is_windows) ) 447 $is_windows = stripos( ftp_systype($this->link), 'win') !== false; 448 449 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) ) { 447 if ( is_null( $is_windows ) ) { 448 $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false; 449 } 450 451 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 ) ) { 450 452 $b = array(); 451 if ( $lucifer[3] < 70 ) 452 $lucifer[3] += 2000;453 else453 if ( $lucifer[3] < 70 ) { 454 $lucifer[3] += 2000; 455 } else { 454 456 $lucifer[3] += 1900; // 4digit year fix 455 $b['isdir'] = ( $lucifer[7] == '<DIR>'); 456 if ( $b['isdir'] ) 457 } 458 $b['isdir'] = ( $lucifer[7] == '<DIR>' ); 459 if ( $b['isdir'] ) { 457 460 $b['type'] = 'd'; 458 else461 } else { 459 462 $b['type'] = 'f'; 460 $b['size'] = $lucifer[7]; 461 $b['month'] = $lucifer[1]; 462 $b['day'] = $lucifer[2]; 463 $b['year'] = $lucifer[3]; 464 $b['hour'] = $lucifer[4]; 463 } 464 $b['size'] = $lucifer[7]; 465 $b['month'] = $lucifer[1]; 466 $b['day'] = $lucifer[2]; 467 $b['year'] = $lucifer[3]; 468 $b['hour'] = $lucifer[4]; 465 469 $b['minute'] = $lucifer[5]; 466 $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);467 $b['am/pm'] = $lucifer[6];468 $b['name'] = $lucifer[8];469 } elseif ( ! $is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {470 $b['time'] = @mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] ); 471 $b['am/pm'] = $lucifer[6]; 472 $b['name'] = $lucifer[8]; 473 } elseif ( ! $is_windows && $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ) ) { 470 474 //echo $line."\n"; 471 $lcount = count( $lucifer);472 if ( $lcount < 8 ) 475 $lcount = count( $lucifer ); 476 if ( $lcount < 8 ) { 473 477 return ''; 474 $b = array(); 475 $b['isdir'] = $lucifer[0]{0} === 'd'; 478 } 479 $b = array(); 480 $b['isdir'] = $lucifer[0]{0} === 'd'; 476 481 $b['islink'] = $lucifer[0]{0} === 'l'; 477 if ( $b['isdir'] ) 482 if ( $b['isdir'] ) { 478 483 $b['type'] = 'd'; 479 elseif ( $b['islink'] )484 } elseif ( $b['islink'] ) { 480 485 $b['type'] = 'l'; 481 else486 } else { 482 487 $b['type'] = 'f'; 483 $b['perms'] = $lucifer[0]; 488 } 489 $b['perms'] = $lucifer[0]; 484 490 $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); 485 491 $b['number'] = $lucifer[1]; 486 $b['owner'] = $lucifer[2];487 $b['group'] = $lucifer[3];488 $b['size'] = $lucifer[4];492 $b['owner'] = $lucifer[2]; 493 $b['group'] = $lucifer[3]; 494 $b['size'] = $lucifer[4]; 489 495 if ( $lcount == 8 ) { 490 sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);491 sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute']);492 $b['time'] = @mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);496 sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); 497 sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); 498 $b['time'] = @mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); 493 499 $b['name'] = $lucifer[7]; 494 500 } else { 495 501 $b['month'] = $lucifer[5]; 496 $b['day'] = $lucifer[6];497 if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {498 $b['year'] = date("Y");499 $b['hour'] = $l2[1];502 $b['day'] = $lucifer[6]; 503 if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { 504 $b['year'] = date( 'Y' ); 505 $b['hour'] = $l2[1]; 500 506 $b['minute'] = $l2[2]; 501 507 } else { 502 $b['year'] = $lucifer[7];503 $b['hour'] = 0;508 $b['year'] = $lucifer[7]; 509 $b['hour'] = 0; 504 510 $b['minute'] = 0; 505 511 } 506 $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );512 $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); 507 513 $b['name'] = $lucifer[8]; 508 514 } … … 518 524 519 525 /** 520 *521 526 * @param string $path 522 527 * @param bool $include_hidden … … 524 529 * @return bool|array 525 530 */ 526 public function dirlist( $path = '.', $include_hidden = true, $recursive = false) {527 if ( $this->is_file( $path) ) {528 $limit_file = basename( $path);529 $path = dirname($path) . '/';531 public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) { 532 if ( $this->is_file( $path ) ) { 533 $limit_file = basename( $path ); 534 $path = dirname( $path ) . '/'; 530 535 } else { 531 536 $limit_file = false; 532 537 } 533 538 534 $pwd = @ftp_pwd($this->link); 535 if ( ! @ftp_chdir($this->link, $path) ) // Cant change to folder = folder doesn't exist 536 return false; 537 $list = @ftp_rawlist($this->link, '-a', false); 538 @ftp_chdir($this->link, $pwd); 539 540 if ( empty($list) ) // Empty array = non-existent folder (real folder will show . at least) 541 return false; 539 $pwd = @ftp_pwd( $this->link ); 540 if ( ! @ftp_chdir( $this->link, $path ) ) { // Cant change to folder = folder doesn't exist 541 return false; 542 } 543 $list = @ftp_rawlist( $this->link, '-a', false ); 544 @ftp_chdir( $this->link, $pwd ); 545 546 if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least) 547 return false; 548 } 542 549 543 550 $dirlist = array(); 544 551 foreach ( $list as $k => $v ) { 545 $entry = $this->parselisting( $v);546 if ( empty( $entry) )552 $entry = $this->parselisting( $v ); 553 if ( empty( $entry ) ) { 547 554 continue; 548 549 if ( '.' == $entry['name'] || '..' == $entry['name'] ) 555 } 556 557 if ( '.' == $entry['name'] || '..' == $entry['name'] ) { 550 558 continue; 551 552 if ( ! $include_hidden && '.' == $entry['name'][0] ) 559 } 560 561 if ( ! $include_hidden && '.' == $entry['name'][0] ) { 553 562 continue; 554 555 if ( $limit_file && $entry['name'] != $limit_file) 563 } 564 565 if ( $limit_file && $entry['name'] != $limit_file ) { 556 566 continue; 567 } 557 568 558 569 $dirlist[ $entry['name'] ] = $entry; … … 560 571 561 572 $ret = array(); 562 foreach ( (array) $dirlist as $struc ) {573 foreach ( (array) $dirlist as $struc ) { 563 574 if ( 'd' == $struc['type'] ) { 564 if ( $recursive ) 565 $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive);566 else575 if ( $recursive ) { 576 $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); 577 } else { 567 578 $struc['files'] = array(); 579 } 568 580 } 569 581 … … 576 588 */ 577 589 public function __destruct() { 578 if ( $this->link ) 579 ftp_close($this->link); 590 if ( $this->link ) { 591 ftp_close( $this->link ); 592 } 580 593 } 581 594 }
Note: See TracChangeset
for help on using the changeset viewer.