X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..784f914b1e4b1c62d6657e86397c2e83bcee4295:/wp-admin/includes/class-wp-filesystem-ftpext.php diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 38536a0e..e1202aed 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -116,12 +116,17 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $tempfile = wp_tempnam($file); $temp = fopen($tempfile, 'w+'); - if ( ! $temp ) + if ( ! $temp ) { + unlink( $tempfile ); return false; - - if ( ! @ftp_fget($this->link, $temp, $file, FTP_BINARY ) ) + } + + if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) { + fclose( $temp ); + unlink( $tempfile ); return false; - + } + fseek( $temp, 0 ); // Skip back to the start of the file being written to $contents = ''; @@ -326,16 +331,14 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { * @param string $file * @return bool */ - public function exists( $file ) { - $path = dirname( $file ); - $filename = basename( $file ); + public function exists($file) { + $list = @ftp_nlist($this->link, $file); - $file_list = @ftp_nlist( $this->link, '-a ' . $path ); - if ( $file_list ) { - $file_list = array_map( 'basename', $file_list ); + if ( empty( $list ) && $this->is_dir( $file ) ) { + return true; // File is an empty directory. } - return $file_list && in_array( $filename, $file_list ); + return !empty($list); //empty list = no file, so invert. } /**