From a39ee17da939fec8d6cfa00b69bf68d990e48b83 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 11 Feb 2008 08:46:11 +0000 Subject: [PATCH] ftp fs tweaks. see #5586 git-svn-id: http://svn.automattic.com/wordpress/trunk@6785 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-filesystem-ftpext.php | 15 +-- .../class-wp-filesystem-ftpsockets.php | 94 ++++++++++--------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 79a5e57e90..528b0d0d35 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -272,19 +272,20 @@ class WP_Filesystem_FTPext{ } function move($source,$destination,$overwrite=false){ 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); - if( !$recursive ) + if ( !$recursive ) return ftp_rmdir($this->link,$file); $filelist = $this->dirlist($file); - foreach($filelist as $filename => $fileinfo){ - echo "Delete $file/$filename
"; + foreach ($filelist as $filename => $fileinfo) { $this->delete($file.'/'.$filename,$recursive); } return ftp_rmdir($this->link,$file); - } + } + function exists($file){ $list = ftp_rawlist($this->link,$file,false); if( ! $list ) diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index 766f0e3853..3a06d574c6 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -23,55 +23,60 @@ class WP_Filesystem_ftpsockets{ 'bmp'=>FTP_BINARY ); - function WP_Filesystem_ftpsockets($opt=''){ + function WP_Filesystem_ftpsockets($opt='') { //Check if possible to use ftp functions. if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) return false; $this->ftp = new FTP(); + //Set defaults: - if( ! isset($opt['port']) || empty($opt['port']) ) - $this->options['port'] = 21; - else - $this->options['port'] = $opt['port']; - - if( ! isset($opt['hostname']) || empty($opt['hostname']) ) - $this->errors['require']['hostname'] = __('Hostname'); - else - $this->options['hostname'] = $opt['hostname']; - - if( isset($opt['base']) && ! empty($opt['base']) ) - $this->wp_base = $opt['base']; - - //Check if the options provided are OK. - if( ! isset($opt['username']) || empty ($opt['username']) ) - $this->errors['require']['username'] = __('Username'); - else - $this->options['username'] = $opt['username']; - - if( ! isset($opt['password']) || empty ($opt['password']) ) - $this->errors['require']['password'] = __('Password'); - else - $this->options['password'] = $opt['password']; + if ( empty($opt['port']) ) + $this->options['port'] = 21; + else + $this->options['port'] = $opt['port']; + + if ( empty($opt['hostname']) ) + $this->errors->add('empty_hostname', __('FTP hostname is required')); + else + $this->options['hostname'] = $opt['hostname']; + + if ( isset($opt['base']) && ! empty($opt['base']) ) + $this->wp_base = $opt['base']; + + // Check if the options provided are OK. + if ( empty ($opt['username']) ) + $this->errors->add('empty_username', __('FTP username is required')); + else + $this->options['username'] = $opt['username']; + + if ( empty ($opt['password']) ) + $this->errors->add('empty_password', __('FTP password is required')); + else + $this->options['password'] = $opt['password']; } - function connect(){ - if( ! $this->ftp ) + + function connect() { + if ( ! $this->ftp ) return false; - 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']; + if ( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ) { + $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); return false; - } - if( ! $this->ftp->login($this->options['username'], $this->options['password']) ){ - $this->errors['auth'] = __('Username/Password incorrect') . ' ' . - $this->options['username'] . ':********@' .$this->options['hostname'] . ':' . $this->options['port']; + } + + if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) { + $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); return false; - } + } + return true; - } - function setDefaultPermissions($perm){ + } + + function setDefaultPermissions($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 = '/'; if( '/' != substr($base, -1) ) $base .= '/'; @@ -252,17 +257,20 @@ class WP_Filesystem_ftpsockets{ } function move($source,$destination,$overwrite=false){ 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); - if( !$recursive ) + if ( !$recursive ) return $this->ftp->rmdir($file); $filelist = $this->dirlist($file); - foreach($filelist as $filename){ + foreach ($filelist as $filename) { $this->delete($file.'/'.$filename,$recursive); - } - } + } + return $this->ftp->rmdir($file); + } + function exists($file){ return $this->ftp->is_exists($file); }