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

@ -273,6 +273,7 @@ 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) )
return ftp_delete($this->link,$file);
@ -280,11 +281,11 @@ class WP_Filesystem_FTPext{
return ftp_rmdir($this->link,$file);
$filelist = $this->dirlist($file);
foreach ($filelist as $filename => $fileinfo) {
echo "Delete $file/$filename<br />";
$this->delete($file.'/'.$filename,$recursive);
}
return ftp_rmdir($this->link,$file);
}
function exists($file){
$list = ftp_rawlist($this->link,$file,false);
if( ! $list )

View File

@ -28,14 +28,15 @@ class WP_Filesystem_ftpsockets{
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']) )
if ( 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');
if ( empty($opt['hostname']) )
$this->errors->add('empty_hostname', __('FTP hostname is required'));
else
$this->options['hostname'] = $opt['hostname'];
@ -43,34 +44,38 @@ class WP_Filesystem_ftpsockets{
$this->wp_base = $opt['base'];
// Check if the options provided are OK.
if( ! isset($opt['username']) || empty ($opt['username']) )
$this->errors['require']['username'] = __('Username');
if ( empty ($opt['username']) )
$this->errors->add('empty_username', __('FTP username is required'));
else
$this->options['username'] = $opt['username'];
if( ! isset($opt['password']) || empty ($opt['password']) )
$this->errors['require']['password'] = __('Password');
if ( empty ($opt['password']) )
$this->errors->add('empty_password', __('FTP password is required'));
else
$this->options['password'] = $opt['password'];
}
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'];
$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'];
$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
return false;
}
return true;
}
function setDefaultPermissions($perm) {
$this->permission = $perm;
}
function find_base_dir($base = '.',$echo = false) {
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
if( empty( $base ) ) $base = '/';
@ -253,6 +258,7 @@ 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) )
return $this->ftp->delete($file);
@ -262,7 +268,9 @@ class WP_Filesystem_ftpsockets{
foreach ($filelist as $filename) {
$this->delete($file.'/'.$filename,$recursive);
}
return $this->ftp->rmdir($file);
}
function exists($file){
return $this->ftp->is_exists($file);
}