- 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-ftpsockets.php
r7033 r7126 30 30 if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) 31 31 return false; 32 $this->ftp = new FTP();32 $this->ftp = new ftp(); 33 33 34 34 //Set defaults: … … 61 61 if ( ! $this->ftp ) 62 62 return false; 63 64 if ( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ) { 63 64 //$this->ftp->Verbose = true; 65 66 if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) { 67 $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); 68 return false; 69 } 70 if ( ! $this->ftp->connect() ) { 65 71 $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); 66 72 return false; … … 72 78 } 73 79 80 $this->ftp->SetType(FTP_AUTOASCII); 81 $this->ftp->Passive(true); 74 82 return true; 75 83 } … … 114 122 return $this->find_base_dir('/',$echo); 115 123 } 124 116 125 function get_base_dir($base = '.'){ 117 126 if( empty($this->wp_base) ) … … 119 128 return $this->wp_base; 120 129 } 130 121 131 function get_contents($file,$type='',$resumepos=0){ 122 132 if( empty($type) ){ … … 125 135 } 126 136 $this->ftp->SetType($type); 127 128 return $this->ftp->get($file); 129 } 137 $temp = tmpfile(); 138 if ( ! $this->ftp->fget($temp, $file) ) { 139 fclose($temp); 140 return false; 141 } 142 fseek($temp, 0); //Skip back to the start of the file being written to 143 $contents = ''; 144 while ( !feof($temp) ) 145 $contents .= fread($temp, 8192); 146 fclose($temp); 147 return $contents; 148 } 149 130 150 function get_contents_array($file){ 131 151 return explode("\n",$this->get_contents($file)); 132 152 } 153 133 154 function put_contents($file,$contents,$type=''){ 134 155 if( empty($type) ){ 135 $extension = substr(strrchr($file name, "."), 1);156 $extension = substr(strrchr($file, "."), 1); 136 157 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 137 158 } … … 141 162 fwrite($temp,$contents); 142 163 fseek($temp, 0); //Skip back to the start of the file being written to 143 $ret = $this->ftp-> put($temp, $file);164 $ret = $this->ftp->fput($file, $temp); 144 165 fclose($temp); 145 166 return $ret; 146 167 } 168 147 169 function cwd(){ 148 170 return $this->ftp->pwd(); 149 171 } 172 150 173 function chgrp($file,$group,$recursive=false){ 151 174 return false; 152 175 } 176 153 177 function chmod($file,$mode=false,$recursive=false){ 154 178 if( ! $mode ) … … 168 192 return true; 169 193 } 194 170 195 function chown($file,$owner,$recursive=false){ 171 196 return false; 172 197 } 198 173 199 function owner($file){ 174 200 $dir = $this->dirlist($file); 175 201 return $dir[$file]['owner']; 176 202 } 203 177 204 function getchmod($file){ 178 205 $dir = $this->dirlist($file); 179 206 return $dir[$file]['permsn']; 180 207 } 208 181 209 function gethchmod($file){ 182 210 //From the PHP.net page for ...? … … 230 258 return $info; 231 259 } 260 232 261 function getnumchmodfromh($mode) { 233 262 $realmode = ""; … … 248 277 return $newmode; 249 278 } 279 250 280 function group($file){ 251 281 $dir = $this->dirlist($file); 252 282 return $dir[$file]['group']; 253 283 } 284 254 285 function copy($source,$destination,$overwrite=false){ 255 286 if( ! $overwrite && $this->exists($destination) ) 256 287 return false; 288 257 289 $content = $this->get_contents($source); 258 $this->put_contents($destination,$content); 259 } 290 if ( !$content ) 291 return false; 292 293 return $this->put_contents($destination,$content); 294 } 295 260 296 function move($source,$destination,$overwrite=false){ 261 297 return $this->ftp->rename($source,$destination); … … 267 303 if ( !$recursive ) 268 304 return $this->ftp->rmdir($file); 269 $filelist = $this->dirlist($file); 270 foreach ($filelist as $filename) { 271 $this->delete($file.'/'.$filename,$recursive); 272 } 273 return $this->ftp->rmdir($file); 305 306 return $this->ftp->mdel($file); 274 307 } 275 308 … … 277 310 return $this->ftp->is_exists($file); 278 311 } 312 279 313 function is_file($file){ 280 //return $this->ftp->file_exists($file); 281 $list = $this->ftp->rawlist($file,'-a'); 282 if( ! $list ) 283 return false; 284 return ($list[0] == '-'); 285 } 314 return $this->is_dir($file) ? false : true; 315 } 316 286 317 function is_dir($path){ 287 $list = $this->ftp->rawlist($file,'-a'); 288 if( ! $list ) 289 return false; 290 return true; 291 } 318 $cwd = $this->cwd(); 319 if ( $this->ftp->chdir($path) ) { 320 $this->ftp->chdir($cwd); 321 return true; 322 } 323 return false; 324 } 325 292 326 function is_readable($file){ 293 327 //Get dir list, Check if the file is writable by the current user?? 294 328 return true; 295 329 } 330 296 331 function is_writable($file){ 297 332 //Get dir list, Check if the file is writable by the current user?? 298 333 return true; 299 334 } 335 300 336 function atime($file){ 301 337 return false; 302 338 } 339 303 340 function mtime($file){ 304 341 return $this->ftp->mdtm($file); 305 342 } 343 306 344 function size($file){ 307 345 return $this->ftp->filesize($file); 308 346 } 347 309 348 function touch($file,$time=0,$atime=0){ 310 349 return false; 311 350 } 351 312 352 function mkdir($path,$chmod=false,$chown=false,$chgrp=false){ 313 353 if( ! $this->ftp->mkdir($path) ) 314 354 return false; 315 355 if( $chmod ) 316 $this->chmod($ chmod);356 $this->chmod($path, $chmod); 317 357 if( $chown ) 318 $this->chown($ chown);358 $this->chown($path, $chown); 319 359 if( $chgrp ) 320 $this->chgrp($ chgrp);360 $this->chgrp($path, $chgrp); 321 361 return true; 322 362 } 363 323 364 function rmdir($path,$recursive=false){ 324 365 if( ! $recursive ) 325 366 return $this->ftp->rmdir($file); 326 return false; 327 //TODO: Recursive Directory delete, Have to delete files from the folder first. 328 //$dir = $this->dirlist($path); 329 //foreach($dir as $file) 330 331 } 367 368 return $this->ftp->mdel($path); 369 } 370 332 371 function dirlist($path='.',$incdot=false,$recursive=false){ 333 372 if( $this->is_file($path) ){ … … 339 378 //if( ! $this->is_dir($path) ) 340 379 // return false; 341 $list = $this->ftp->rawlist($path,'-a'); 342 //var_dump($list); 380 $list = $this->ftp->dirlist($path); 343 381 if( ! $list ) 344 382 return false; … … 347 385 348 386 $ret = array(); 349 foreach($list as $line){ 350 $struc = array(); 351 $current = preg_split("/[\s]+/",$line,9); 352 $struc['name'] = str_replace('//','',$current[8]); 353 354 if( '.' == $struc['name'][0] && !$incdot) 355 continue; 356 if( $limitFile && $struc['name'] != $limitFile) 357 continue; 358 359 $struc['perms'] = $current[0]; 360 $struc['permsn'] = $this->getnumchmodfromh($current[0]); 361 $struc['number'] = $current[1]; 362 $struc['owner'] = $current[2]; 363 $struc['group'] = $current[3]; 364 $struc['size'] = $current[4]; 365 $struc['lastmod'] = $current[5].' '.$current[6]; 366 $struc['time'] = $current[7]; 367 368 $struc['type'] = ('d' == $struc['perms'][0] || 'l' == $struc['perms'][0] ) ? 'folder' : 'file'; 369 if('folder' == $struc['type'] ){ 387 foreach ( $list as $struc ) { 388 389 if ( 'd' == $struc['type'] ) { 370 390 $struc['files'] = array(); 371 391 372 if ( $incdot ){392 if ( $incdot ){ 373 393 //We're including the doted starts 374 394 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder … … 386 406 return $ret; 387 407 } 408 388 409 function __destruct(){ 389 410 $this->ftp->quit();
Note: See TracChangeset
for help on using the changeset viewer.