ftp fs tweaks. see #5586

git-svn-id: http://svn.automattic.com/wordpress/trunk@6785 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-11 08:46:11 +00:00
parent b5aefdfc0c
commit a39ee17da9
2 changed files with 59 additions and 50 deletions

View File

@ -272,19 +272,20 @@ class WP_Filesystem_FTPext{
} }
function move($source,$destination,$overwrite=false){ function move($source,$destination,$overwrite=false){
return ftp_rename($this->link,$source,$destination); return ftp_rename($this->link,$source,$destination);
} }
function delete($file,$recursive=false){
if( $this->is_file($file) ) function delete($file,$recursive=false) {
if ( $this->is_file($file) )
return ftp_delete($this->link,$file); return ftp_delete($this->link,$file);
if( !$recursive ) if ( !$recursive )
return ftp_rmdir($this->link,$file); return ftp_rmdir($this->link,$file);
$filelist = $this->dirlist($file); $filelist = $this->dirlist($file);
foreach($filelist as $filename => $fileinfo){ foreach ($filelist as $filename => $fileinfo) {
echo "Delete $file/$filename<br />";
$this->delete($file.'/'.$filename,$recursive); $this->delete($file.'/'.$filename,$recursive);
} }
return ftp_rmdir($this->link,$file); return ftp_rmdir($this->link,$file);
} }
function exists($file){ function exists($file){
$list = ftp_rawlist($this->link,$file,false); $list = ftp_rawlist($this->link,$file,false);
if( ! $list ) if( ! $list )

View File

@ -23,55 +23,60 @@ class WP_Filesystem_ftpsockets{
'bmp'=>FTP_BINARY 'bmp'=>FTP_BINARY
); );
function WP_Filesystem_ftpsockets($opt=''){ function WP_Filesystem_ftpsockets($opt='') {
//Check if possible to use ftp functions. //Check if possible to use ftp functions.
if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
return false; return false;
$this->ftp = new FTP(); $this->ftp = new FTP();
//Set defaults: //Set defaults:
if( ! isset($opt['port']) || empty($opt['port']) ) if ( empty($opt['port']) )
$this->options['port'] = 21; $this->options['port'] = 21;
else else
$this->options['port'] = $opt['port']; $this->options['port'] = $opt['port'];
if( ! isset($opt['hostname']) || empty($opt['hostname']) ) if ( empty($opt['hostname']) )
$this->errors['require']['hostname'] = __('Hostname'); $this->errors->add('empty_hostname', __('FTP hostname is required'));
else else
$this->options['hostname'] = $opt['hostname']; $this->options['hostname'] = $opt['hostname'];
if( isset($opt['base']) && ! empty($opt['base']) ) if ( isset($opt['base']) && ! empty($opt['base']) )
$this->wp_base = $opt['base']; $this->wp_base = $opt['base'];
//Check if the options provided are OK. // Check if the options provided are OK.
if( ! isset($opt['username']) || empty ($opt['username']) ) if ( empty ($opt['username']) )
$this->errors['require']['username'] = __('Username'); $this->errors->add('empty_username', __('FTP username is required'));
else else
$this->options['username'] = $opt['username']; $this->options['username'] = $opt['username'];
if( ! isset($opt['password']) || empty ($opt['password']) ) if ( empty ($opt['password']) )
$this->errors['require']['password'] = __('Password'); $this->errors->add('empty_password', __('FTP password is required'));
else else
$this->options['password'] = $opt['password']; $this->options['password'] = $opt['password'];
} }
function connect(){
if( ! $this->ftp ) function connect() {
if ( ! $this->ftp )
return false; return false;
if( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ){ if ( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ) {
$this->errors['server'] = __('Failed to connect to FTP Server') . ' ' . $this->options['hostname'] . ':' . $this->options['port']; $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
return false; return false;
} }
if( ! $this->ftp->login($this->options['username'], $this->options['password']) ){
$this->errors['auth'] = __('Username/Password incorrect') . ' ' . if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) {
$this->options['username'] . ':********@' .$this->options['hostname'] . ':' . $this->options['port']; $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
return false; return false;
} }
return true; return true;
} }
function setDefaultPermissions($perm){
function setDefaultPermissions($perm) {
$this->permission = $perm; $this->permission = $perm;
} }
function find_base_dir($base = '.',$echo = false){
function find_base_dir($base = '.',$echo = false) {
if( empty( $base ) || '.' == $base ) $base = $this->cwd(); if( empty( $base ) || '.' == $base ) $base = $this->cwd();
if( empty( $base ) ) $base = '/'; if( empty( $base ) ) $base = '/';
if( '/' != substr($base, -1) ) $base .= '/'; if( '/' != substr($base, -1) ) $base .= '/';
@ -252,17 +257,20 @@ class WP_Filesystem_ftpsockets{
} }
function move($source,$destination,$overwrite=false){ function move($source,$destination,$overwrite=false){
return $this->ftp->rename($source,$destination); return $this->ftp->rename($source,$destination);
} }
function delete($file,$recursive=false){
if( $this->is_file($file) ) function delete($file,$recursive=false) {
if ( $this->is_file($file) )
return $this->ftp->delete($file); return $this->ftp->delete($file);
if( !$recursive ) if ( !$recursive )
return $this->ftp->rmdir($file); return $this->ftp->rmdir($file);
$filelist = $this->dirlist($file); $filelist = $this->dirlist($file);
foreach($filelist as $filename){ foreach ($filelist as $filename) {
$this->delete($file.'/'.$filename,$recursive); $this->delete($file.'/'.$filename,$recursive);
} }
} return $this->ftp->rmdir($file);
}
function exists($file){ function exists($file){
return $this->ftp->is_exists($file); return $this->ftp->is_exists($file);
} }