--- a/wp/wp-admin/includes/class-wp-filesystem-ftpext.php Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-admin/includes/class-wp-filesystem-ftpext.php Mon Oct 14 17:39:30 2019 +0200
@@ -10,14 +10,17 @@
* WordPress Filesystem Class for implementing FTP.
*
* @since 2.5.0
- * @package WordPress
- * @subpackage Filesystem
- * @uses WP_Filesystem_Base Extends class
+ *
+ * @see WP_Filesystem_Base
*/
class WP_Filesystem_FTPext extends WP_Filesystem_Base {
public $link;
- public function __construct($opt='') {
+ /**
+ *
+ * @param array $opt
+ */
+ public function __construct( $opt = '' ) {
$this->method = 'ftpext';
$this->errors = new WP_Error();
@@ -58,6 +61,10 @@
$this->options['ssl'] = true;
}
+ /**
+ *
+ * @return bool
+ */
public function connect() {
if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
@@ -65,12 +72,22 @@
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
if ( ! $this->link ) {
- $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
+ $this->errors->add( 'connect',
+ /* translators: %s: hostname:port */
+ sprintf( __( 'Failed to connect to FTP Server %s' ),
+ $this->options['hostname'] . ':' . $this->options['port']
+ )
+ );
return false;
}
- if ( ! @ftp_login($this->link,$this->options['username'], $this->options['password']) ) {
- $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
+ if ( ! @ftp_login( $this->link,$this->options['username'], $this->options['password'] ) ) {
+ $this->errors->add( 'auth',
+ /* translators: %s: username */
+ sprintf( __( 'Username/Password incorrect for %s' ),
+ $this->options['username']
+ )
+ );
return false;
}
@@ -83,18 +100,28 @@
}
/**
- * @param string $file
- * @return false|string
+ * Retrieves the file contents.
+ *
+ * @since 2.5.0
+ *
+ * @param string $file Filename.
+ * @return string|false File contents on success, false if no temp file could be opened,
+ * or if the file couldn't be retrieved.
*/
public function get_contents( $file ) {
$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 = '';
@@ -108,6 +135,7 @@
}
/**
+ *
* @param string $file
* @return array
*/
@@ -116,6 +144,7 @@
}
/**
+ *
* @param string $file
* @param string $contents
* @param bool|int $mode
@@ -124,8 +153,11 @@
public function put_contents($file, $contents, $mode = false ) {
$tempfile = wp_tempnam($file);
$temp = fopen( $tempfile, 'wb+' );
- if ( ! $temp )
+
+ if ( ! $temp ) {
+ unlink( $tempfile );
return false;
+ }
mbstring_binary_safe_encoding();
@@ -153,6 +185,7 @@
}
/**
+ *
* @return string
*/
public function cwd() {
@@ -163,6 +196,7 @@
}
/**
+ *
* @param string $dir
* @return bool
*/
@@ -171,6 +205,7 @@
}
/**
+ *
* @param string $file
* @param int $mode
* @param bool $recursive
@@ -200,6 +235,7 @@
}
/**
+ *
* @param string $file
* @return string
*/
@@ -208,6 +244,7 @@
return $dir[$file]['owner'];
}
/**
+ *
* @param string $file
* @return string
*/
@@ -215,7 +252,9 @@
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
}
+
/**
+ *
* @param string $file
* @return string
*/
@@ -240,7 +279,9 @@
return false;
return $this->put_contents($destination, $content, $mode);
}
+
/**
+ *
* @param string $source
* @param string $destination
* @param bool $overwrite
@@ -249,7 +290,9 @@
public function move($source, $destination, $overwrite = false) {
return ftp_rename($this->link, $source, $destination);
}
+
/**
+ *
* @param string $file
* @param bool $recursive
* @param string $type
@@ -269,7 +312,9 @@
$this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] );
return @ftp_rmdir($this->link, $file);
}
+
/**
+ *
* @param string $file
* @return bool
*/
@@ -282,14 +327,18 @@
return !empty($list); //empty list = no file, so invert.
}
+
/**
+ *
* @param string $file
* @return bool
*/
public function is_file($file) {
return $this->exists($file) && !$this->is_dir($file);
}
+
/**
+ *
* @param string $path
* @return bool
*/
@@ -304,41 +353,52 @@
}
/**
+ *
* @param string $file
* @return bool
*/
public function is_readable($file) {
return true;
}
+
/**
+ *
* @param string $file
* @return bool
*/
public function is_writable($file) {
return true;
}
+
/**
+ *
* @param string $file
* @return bool
*/
public function atime($file) {
return false;
}
+
/**
+ *
* @param string $file
* @return int
*/
public function mtime($file) {
return ftp_mdtm($this->link, $file);
}
+
/**
+ *
* @param string $file
* @return int
*/
public function size($file) {
return ftp_size($this->link, $file);
}
+
/**
+ *
* @param string $file
* @return bool
*/
@@ -347,6 +407,7 @@
}
/**
+ *
* @param string $path
* @param mixed $chmod
* @param mixed $chown
@@ -365,6 +426,7 @@
}
/**
+ *
* @param string $path
* @param bool $recursive
* @return bool
@@ -374,12 +436,13 @@
}
/**
+ *
* @staticvar bool $is_windows
* @param string $line
- * @return string
+ * @return array
*/
public function parselisting($line) {
- static $is_windows;
+ static $is_windows = null;
if ( is_null($is_windows) )
$is_windows = stripos( ftp_systype($this->link), 'win') !== false;
@@ -418,6 +481,7 @@
else
$b['type'] = 'f';
$b['perms'] = $lucifer[0];
+ $b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
@@ -445,13 +509,15 @@
}
// Replace symlinks formatted as "source -> target" with just the source name
- if ( $b['islink'] )
+ if ( isset( $b['islink'] ) && $b['islink'] ) {
$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
+ }
return $b;
}
/**
+ *
* @param string $path
* @param bool $include_hidden
* @param bool $recursive
@@ -506,6 +572,8 @@
return $ret;
}
+ /**
+ */
public function __destruct() {
if ( $this->link )
ftp_close($this->link);