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:
parent
b5aefdfc0c
commit
a39ee17da9
|
@ -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<br />";
|
||||
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 )
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue