From 568d64e73ec1ec4ecfcb3b290dfc9a77924224da Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 16 Mar 2008 09:49:10 +0000 Subject: [PATCH] FTP CWD fixes from DD32. see #6245 git-svn-id: http://svn.automattic.com/wordpress/trunk@7327 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-ftp.php | 2 +- wp-admin/includes/class-wp-filesystem-ftpext.php | 16 ++++++++++------ .../includes/class-wp-filesystem-ftpsockets.php | 8 +++++--- wp-admin/includes/file.php | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/wp-admin/includes/class-ftp.php b/wp-admin/includes/class-ftp.php index bc2720ab6c..c10526bddb 100644 --- a/wp-admin/includes/class-ftp.php +++ b/wp-admin/includes/class-ftp.php @@ -317,7 +317,7 @@ class ftp_base { function pwd() { if(!$this->_exec("PWD", "pwd")) return FALSE; if(!$this->_checkCode()) return FALSE; - return ereg_replace("^[0-9]{3} \"(.+)\" .+".CRLF, "\\1", $this->_message); + return ereg_replace("^[0-9]{3} \"(.+)\".+", "\\1", $this->_message); } function cdup() { diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 9645f8d892..88d806872c 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -162,7 +162,10 @@ class WP_Filesystem_FTPext{ return $ret; } function cwd(){ - return ftp_pwd($this->link); + $cwd = ftp_pwd($this->link); + if( $cwd ) + $cwd = trailingslashit($cwd); + return $cwd; } function chdir($dir){ return @ftp_chdir($dir); @@ -308,8 +311,9 @@ class WP_Filesystem_FTPext{ } function is_dir($path){ $cwd = $this->cwd(); - @ftp_chdir($this->link, $path); - if ( $this->cwd() != $cwd ) { + $result = @ftp_chdir($this->link, $path); + if( $result && $path == $this->cwd() || + $this->cwd() != $cwd ) { @ftp_chdir($this->link, $cwd); return true; } @@ -425,9 +429,9 @@ class WP_Filesystem_FTPext{ } else { $limitFile = false; } - //if( ! $this->is_dir($path) ) - // return false; - $list = ftp_rawlist($this->link , '-a ' . $path, false); + + $list = @ftp_rawlist($this->link , '-a ' . $path, false); + if ( $list === false ) return false; diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index 6b60e9b308..b9f188ecad 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -176,7 +176,10 @@ class WP_Filesystem_ftpsockets{ } function cwd(){ - return $this->ftp->pwd(); + $cwd = $this->ftp->pwd(); + if( $cwd ) + $cwd = trailingslashit($cwd); + return $cwd; } function chdir($file){ @@ -388,8 +391,7 @@ class WP_Filesystem_ftpsockets{ } else { $limitFile = false; } - //if( ! $this->is_dir($path) ) - // return false; + $list = $this->ftp->dirlist($path); if( ! $list ) return false; diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 4f5d96b7c8..e7ccfcc386 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -325,7 +325,7 @@ function get_filesystem_method() { } if ( extension_loaded('ftp') ) return 'ftpext'; - if ( extension_loaded('sockets') ) return 'ftpsockets'; + if ( extension_loaded('sockets') || function_exists('fsockopen') ) return 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread return false; }