-
+ 4B7FAB2CADF7C6B81EFCE687E49D6EEECA0D07A582D58C121AE6AAA03B3CB9F3970A6708BCF676C921DA2A0C264A34D5E22B94CE2727665AB1A0C1989336F618
mp-wp/wp-admin/includes/class-wp-filesystem-ftpsockets.php
(0 . 0)(1 . 325)
31152 <?php
31153 /**
31154 * WordPress FTP Sockets Filesystem.
31155 *
31156 * @package WordPress
31157 * @subpackage Filesystem
31158 */
31159
31160 /**
31161 * WordPress Filesystem Class for implementing FTP Sockets.
31162 *
31163 * @since 2.5
31164 * @package WordPress
31165 * @subpackage Filesystem
31166 * @uses WP_Filesystem_Base Extends class
31167 */
31168 class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
31169 var $ftp = false;
31170 var $timeout = 5;
31171 var $errors;
31172 var $options = array();
31173
31174 var $permission = null;
31175
31176 function WP_Filesystem_ftpsockets($opt = '') {
31177 $this->method = 'ftpsockets';
31178 $this->errors = new WP_Error();
31179
31180 //Check if possible to use ftp functions.
31181 if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
31182 return false;
31183 $this->ftp = new ftp();
31184
31185 //Set defaults:
31186 if ( empty($opt['port']) )
31187 $this->options['port'] = 21;
31188 else
31189 $this->options['port'] = $opt['port'];
31190
31191 if ( empty($opt['hostname']) )
31192 $this->errors->add('empty_hostname', __('FTP hostname is required'));
31193 else
31194 $this->options['hostname'] = $opt['hostname'];
31195
31196 if ( isset($opt['base']) && ! empty($opt['base']) )
31197 $this->wp_base = $opt['base'];
31198
31199 // Check if the options provided are OK.
31200 if ( empty ($opt['username']) )
31201 $this->errors->add('empty_username', __('FTP username is required'));
31202 else
31203 $this->options['username'] = $opt['username'];
31204
31205 if ( empty ($opt['password']) )
31206 $this->errors->add('empty_password', __('FTP password is required'));
31207 else
31208 $this->options['password'] = $opt['password'];
31209 }
31210
31211 function connect() {
31212 if ( ! $this->ftp )
31213 return false;
31214
31215 //$this->ftp->Verbose = true;
31216
31217 if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
31218 $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
31219 return false;
31220 }
31221 if ( ! $this->ftp->connect() ) {
31222 $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
31223 return false;
31224 }
31225
31226 if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) {
31227 $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
31228 return false;
31229 }
31230
31231 $this->ftp->SetType(FTP_AUTOASCII);
31232 $this->ftp->Passive(true);
31233 return true;
31234 }
31235
31236 function setDefaultPermissions($perm) {
31237 $this->permission = $perm;
31238 }
31239
31240 function get_contents($file, $type = '', $resumepos = 0) {
31241 if( ! $this->exists($file) )
31242 return false;
31243
31244 if( empty($type) )
31245 $type = FTP_AUTOASCII;
31246 $this->ftp->SetType($type);
31247
31248 $temp = wp_tempnam( $file );
31249
31250 if ( ! $temphandle = fopen($temp, 'w+') )
31251 return false;
31252
31253 if ( ! $this->ftp->fget($temphandle, $file) ) {
31254 fclose($temphandle);
31255 unlink($temp);
31256 return ''; //Blank document, File does exist, Its just blank.
31257 }
31258
31259 fseek($temphandle, 0); //Skip back to the start of the file being written to
31260 $contents = '';
31261
31262 while ( ! feof($temphandle) )
31263 $contents .= fread($temphandle, 8192);
31264
31265 fclose($temphandle);
31266 unlink($temp);
31267 return $contents;
31268 }
31269
31270 function get_contents_array($file) {
31271 return explode("\n", $this->get_contents($file) );
31272 }
31273
31274 function put_contents($file, $contents, $type = '' ) {
31275 if( empty($type) )
31276 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
31277
31278 $this->ftp->SetType($type);
31279
31280 $temp = wp_tempnam( $file );
31281 if ( ! $temphandle = fopen($temp, 'w+') ){
31282 unlink($temp);
31283 return false;
31284 }
31285
31286 fwrite($temphandle, $contents);
31287 fseek($temphandle, 0); //Skip back to the start of the file being written to
31288
31289 $ret = $this->ftp->fput($file, $temphandle);
31290
31291 fclose($temphandle);
31292 unlink($temp);
31293 return $ret;
31294 }
31295
31296 function cwd() {
31297 $cwd = $this->ftp->pwd();
31298 if( $cwd )
31299 $cwd = trailingslashit($cwd);
31300 return $cwd;
31301 }
31302
31303 function chdir($file) {
31304 return $this->ftp->chdir($file);
31305 }
31306
31307 function chgrp($file, $group, $recursive = false ) {
31308 return false;
31309 }
31310
31311 function chmod($file, $mode = false, $recursive = false ) {
31312 if( ! $mode )
31313 $mode = $this->permission;
31314 if( ! $mode )
31315 return false;
31316 //if( ! $this->exists($file) )
31317 // return false;
31318 if( ! $recursive || ! $this->is_dir($file) ) {
31319 return $this->ftp->chmod($file,$mode);
31320 }
31321 //Is a directory, and we want recursive
31322 $filelist = $this->dirlist($file);
31323 foreach($filelist as $filename){
31324 $this->chmod($file . '/' . $filename, $mode, $recursive);
31325 }
31326 return true;
31327 }
31328
31329 function chown($file, $owner, $recursive = false ) {
31330 return false;
31331 }
31332
31333 function owner($file) {
31334 $dir = $this->dirlist($file);
31335 return $dir[$file]['owner'];
31336 }
31337
31338 function getchmod($file) {
31339 $dir = $this->dirlist($file);
31340 return $dir[$file]['permsn'];
31341 }
31342
31343 function group($file) {
31344 $dir = $this->dirlist($file);
31345 return $dir[$file]['group'];
31346 }
31347
31348 function copy($source, $destination, $overwrite = false ) {
31349 if( ! $overwrite && $this->exists($destination) )
31350 return false;
31351
31352 $content = $this->get_contents($source);
31353 if ( false === $content )
31354 return false;
31355
31356 return $this->put_contents($destination, $content);
31357 }
31358
31359 function move($source, $destination, $overwrite = false ) {
31360 return $this->ftp->rename($source, $destination);
31361 }
31362
31363 function delete($file, $recursive = false ) {
31364 if ( $this->is_file($file) )
31365 return $this->ftp->delete($file);
31366 if ( !$recursive )
31367 return $this->ftp->rmdir($file);
31368
31369 return $this->ftp->mdel($file);
31370 }
31371
31372 function exists($file) {
31373 return $this->ftp->is_exists($file);
31374 }
31375
31376 function is_file($file) {
31377 return $this->is_dir($file) ? false : true;
31378 }
31379
31380 function is_dir($path) {
31381 $cwd = $this->cwd();
31382 if ( $this->chdir($path) ) {
31383 $this->chdir($cwd);
31384 return true;
31385 }
31386 return false;
31387 }
31388
31389 function is_readable($file) {
31390 //Get dir list, Check if the file is writable by the current user??
31391 return true;
31392 }
31393
31394 function is_writable($file) {
31395 //Get dir list, Check if the file is writable by the current user??
31396 return true;
31397 }
31398
31399 function atime($file) {
31400 return false;
31401 }
31402
31403 function mtime($file) {
31404 return $this->ftp->mdtm($file);
31405 }
31406
31407 function size($file) {
31408 return $this->ftp->filesize($file);
31409 }
31410
31411 function touch($file, $time = 0, $atime = 0 ) {
31412 return false;
31413 }
31414
31415 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
31416 if( ! $this->ftp->mkdir($path) )
31417 return false;
31418 if( $chmod )
31419 $this->chmod($path, $chmod);
31420 if( $chown )
31421 $this->chown($path, $chown);
31422 if( $chgrp )
31423 $this->chgrp($path, $chgrp);
31424 return true;
31425 }
31426
31427 function rmdir($path, $recursive = false ) {
31428 if( ! $recursive )
31429 return $this->ftp->rmdir($path);
31430
31431 return $this->ftp->mdel($path);
31432 }
31433
31434 function dirlist($path = '.', $incdot = false, $recursive = false ) {
31435 if( $this->is_file($path) ) {
31436 $limitFile = basename($path);
31437 $path = dirname($path) . '/';
31438 } else {
31439 $limitFile = false;
31440 }
31441
31442 $list = $this->ftp->dirlist($path);
31443 if( ! $list )
31444 return false;
31445 if( empty($list) )
31446 return array();
31447
31448 $ret = array();
31449 foreach ( $list as $struc ) {
31450
31451 if ( 'd' == $struc['type'] ) {
31452 $struc['files'] = array();
31453
31454 if ( $incdot ){
31455 //We're including the doted starts
31456 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
31457 if ($recursive)
31458 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
31459 }
31460 } else { //No dots
31461 if ($recursive)
31462 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
31463 }
31464 }
31465 //File
31466 $ret[$struc['name']] = $struc;
31467 }
31468 return $ret;
31469 }
31470
31471 function __destruct() {
31472 $this->ftp->quit();
31473 }
31474 }
31475
31476 ?>