$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
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, It's 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) )
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);
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'];
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) {
}
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;
}
$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 ) {
$ret[ $struc['name'] ] = $struc;
}
+
+ reset_mbstring_encoding();
+
return $ret;
}