]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-filesystem-ftpsockets.php
WordPress 3.8.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-filesystem-ftpsockets.php
index 1c931e19281c5a600c63e294d9b0cf524f3f9da7..817dd08e0bfeda9146b4beb270960c9f5233a119 100644 (file)
@@ -23,12 +23,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                $this->method = 'ftpsockets';
                $this->errors = new WP_Error();
 
-               //Check if possible to use ftp functions.
+               // 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 ( empty($opt['port']) )
                        $this->options['port'] = 21;
                else
@@ -75,32 +74,35 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                        return false;
                }
 
-               $this->ftp->SetType(FTP_AUTOASCII);
-               $this->ftp->Passive(true);
-               $this->ftp->setTimeout(FS_TIMEOUT);
+               $this->ftp->SetType( FTP_BINARY );
+               $this->ftp->Passive( true );
+               $this->ftp->setTimeout( FS_TIMEOUT );
                return true;
        }
 
-       function get_contents($file, $type = '', $resumepos = 0) {
+       function get_contents( $file ) {
                if ( ! $this->exists($file) )
                        return false;
 
-               if ( empty($type) )
-                       $type = FTP_AUTOASCII;
-               $this->ftp->SetType($type);
-
                $temp = wp_tempnam( $file );
 
                if ( ! $temphandle = fopen($temp, 'w+') )
                        return false;
 
+               mbstring_binary_safe_encoding();
+
                if ( ! $this->ftp->fget($temphandle, $file) ) {
                        fclose($temphandle);
                        unlink($temp);
-                       return ''; //Blank document, File does exist, Its just blank.
+
+                       reset_mbstring_encoding();
+
+                       return ''; // Blank document, File does exist, It's just blank.
                }
 
-               fseek($temphandle, 0); //Skip back to the start of the file being written to
+               reset_mbstring_encoding();
+
+               fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
                $contents = '';
 
                while ( ! feof($temphandle) )
@@ -122,14 +124,25 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                        return false;
                }
 
-               fwrite($temphandle, $contents);
-               fseek($temphandle, 0); //Skip back to the start of the file being written to
+               // The FTP class uses string functions internally during file download/upload
+               mbstring_binary_safe_encoding();
+
+               $bytes_written = fwrite( $temphandle, $contents );
+               if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
+                       fclose( $temphandle );
+                       unlink( $temp );
+
+                       reset_mbstring_encoding();
+
+                       return false;
+               }
 
-               $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
-               $this->ftp->SetType($type);
+               fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
 
                $ret = $this->ftp->fput($file, $temphandle);
 
+               reset_mbstring_encoding();
+
                fclose($temphandle);
                unlink($temp);
 
@@ -174,10 +187,6 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                return $this->ftp->chmod($file, $mode);
        }
 
-       function chown($file, $owner, $recursive = false ) {
-               return false;
-       }
-
        function owner($file) {
                $dir = $this->dirlist($file);
                return $dir[$file]['owner'];
@@ -219,8 +228,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                return $this->ftp->mdel($file);
        }
 
-       function exists($file) {
-               return $this->ftp->is_exists($file);
+       function exists( $file ) {
+               $list = $this->ftp->nlist( $file );
+               return !empty( $list ); //empty list = no file, so invert.
+               // return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server
        }
 
        function is_file($file) {
@@ -241,12 +252,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
        }
 
        function is_readable($file) {
-               //Get dir list, Check if the file is writable by the current user??
                return true;
        }
 
        function is_writable($file) {
-               //Get dir list, Check if the file is writable by the current user??
                return true;
        }
 
@@ -295,9 +304,15 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
                        $limit_file = false;
                }
 
+               mbstring_binary_safe_encoding();
+
                $list = $this->ftp->dirlist($path);
-               if ( empty($list) && !$this->exists($path) )
+               if ( empty( $list ) && ! $this->exists( $path ) ) {
+
+                       reset_mbstring_encoding();
+
                        return false;
+               }
 
                $ret = array();
                foreach ( $list as $struc ) {
@@ -324,6 +339,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
 
                        $ret[ $struc['name'] ] = $struc;
                }
+
+               reset_mbstring_encoding();
+
                return $ret;
        }