WP_Filesystem_FTPext
- Since
- 2.5.0
- Source
wp-admin/includes/class-wp-filesystem-ftpext.php:16
WordPress Filesystem Class for implementing FTP.
Compatibility
- WordPress
- since 2.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 1
$linkFTP\Connection|resource|falsepublic
Methods · 28
- __construct()Constructor.
- connect()Connects filesystem.
- get_contents()Reads entire file into a string.
- get_contents_array()Reads entire file into an array.
- put_contents()Writes a string to a file.
- cwd()Gets the current working directory.
- chdir()Changes current directory.
- chmod()Changes filesystem permissions.
- owner()Gets the file owner.
- getchmod()Gets the permissions of the specified file or filepath in their octal format.
- group()Gets the file's group.
- copy()Copies a file.
- move()Moves a file or directory.
- delete()Deletes a file or directory.
- exists()Checks if a file or directory exists.
- is_file()Checks if resource is a file.
- is_dir()Checks if resource is a directory.
- is_readable()Checks if a file is readable.
- is_writable()Checks if a file or directory is writable.
- atime()Gets the file's last access time.
- mtime()Gets the file modification time.
- size()Gets the file size (in bytes).
- touch()Sets the access and modification times of a file.
- mkdir()Creates a directory.
- rmdir()Deletes a directory.
- parselisting()Parses an individual entry from the FTP LIST command output.
- dirlist()Gets details for files in a directory or a specific file.
- __destruct()Destructor.
Source code
class WP_Filesystem_FTPext extends WP_Filesystem_Base { /** * @since 2.5.0 * @var FTP\Connection|resource|false */ public $link; /** * Constructor. * * @since 2.5.0 * * @param array $opt */ public function __construct( $opt = '' ) { $this->method = 'ftpext'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! extension_loaded( 'ftp' ) ) { $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) ); return; } // This class uses the timeout on a per-connection basis, others use it on a per-action basis. if ( ! defined( 'FS_TIMEOUT' ) ) { define( 'FS_TIMEOUT', 4 * MINUTE_IN_SECONDS ); } if ( empty( $opt['port'] ) ) { $this->options['port'] = 21; } else { $this->options['port'] = $opt['port']; } if ( empty( $opt['hostname'] ) ) { $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) ); } else { $this->options['hostname'] = $opt['hostname']; } // Check if the options provided are OK. if ( empty( $opt['username'] ) ) { $this->errors->add( 'empty_username', __( 'FTP username is required' ) ); } else { $this->options['username'] = $opt['username']; } if ( empty( $opt['password'] ) ) { $this->errors->add( 'empty_password', __( 'FTP password is required' ) ); } else { $this->options['password'] = $opt['password']; } $this->options['ssl'] = false; if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { $this->options['ssl'] = true; } } /** * Connects filesystem. * * @since 2.5.0 * * @return bool True on success, false on failure. */ 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 ); } else { $this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT ); } if ( ! $this->link ) { $this->errors->add( 'connect', sprintf(Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/class-wp-filesystem-ftpext.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.