: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Gets the file's last access time.
* @param string $file Path to file.
* @return int|false Unix timestamp representing last access time, false on failure.
public function atime( $file ) {
* Gets the file modification time.
* @param string $file Path to file.
* @return int|false Unix timestamp representing modification time, false on failure.
public function mtime( $file ) {
return ftp_mdtm( $this->link, $file );
* Gets the file size (in bytes).
* @param string $file Path to file.
* @return int|false Size of the file in bytes on success, false on failure.
public function size( $file ) {
$size = ftp_size( $this->link, $file );
return ( $size > -1 ) ? $size : false;
* Sets the access and modification times of a file.
* Note: If $file doesn't exist, it will be created.
* @param string $file Path to file.
* @param int $time Optional. Modified time to set for file.
* @param int $atime Optional. Access time to set for file.
* @return bool True on success, false on failure.
public function touch( $file, $time = 0, $atime = 0 ) {
* @param string $path Path for new directory.
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod).
* @param string|int|false $chown Optional. A user name or number (or false to skip chown).
* @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp).
* @return bool True on success, false on failure.
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path );
if ( ! ftp_mkdir( $this->link, $path ) ) {
$this->chmod( $path, $chmod );
* @param string $path Path to directory.
* @param bool $recursive Optional. Whether to recursively remove files/directories.
* @return bool True on success, false on failure.
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
* Array of file information.
* @type string $name Name of the file or directory.
* @type string $perms *nix representation of permissions.
* @type string $permsn Octal representation of permissions.
* @type string|false $number File number as a string, or false if not available.
* @type string|false $owner Owner name or ID, or false if not available.
* @type string|false $group File permissions group, or false if not available.
* @type string|false $size Size of file in bytes as a string, or false if not available.
* @type string|false $lastmodunix Last modified unix timestamp as a string, or false if not available.
* @type string|false $lastmod Last modified month (3 letters) and day (without leading 0), or
* false if not available.
* @type string|false $time Last modified time, or false if not available.
* @type string $type Type of resource. 'f' for file, 'd' for directory, 'l' for link.
* @type array|false $files If a directory and `$recursive` is true, contains another array of files.
* False if unable to list directory contents.
public function parselisting( $line ) {
static $is_windows = null;
if ( is_null( $is_windows ) ) {
$is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) {
if ( $lucifer[3] < 70 ) {
$lucifer[3] += 1900; // 4-digit year fix.
$b['isdir'] = ( '<DIR>' === $lucifer[7] );
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) === 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} elseif ( ! $is_windows ) {
$lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY );
$lcount = count( $lucifer );
$b['isdir'] = 'd' === $lucifer[0][0];
$b['islink'] = 'l' === $lucifer[0][0];
} elseif ( $b['islink'] ) {
$b['perms'] = $lucifer[0];
$b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
$b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['name'] = $lucifer[7];
$b['month'] = $lucifer[5];
if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
$b['year'] = gmdate( 'Y' );
$b['year'] = $lucifer[7];
$b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
$b['name'] = $lucifer[8];
// Replace symlinks formatted as "source -> target" with just the source name.
if ( isset( $b['islink'] ) && $b['islink'] ) {
$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
* Gets details for files in a directory or a specific file.
* @param string $path Path to directory or file.
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
* @param bool $recursive Optional. Whether to recursively include file details in nested directories.
* Array of arrays containing file information. False if unable to list directory contents.
* Array of file information. Note that some elements may not be available on all filesystems.
* @type string $name Name of the file or directory.
* @type string $perms *nix representation of permissions.
* @type string $permsn Octal representation of permissions.
* @type int|string|false $number File number. May be a numeric string. False if not available.
* @type string|false $owner Owner name or ID, or false if not available.
* @type string|false $group File permissions group, or false if not available.
* @type int|string|false $size Size of file in bytes. May be a numeric string.
* False if not available.
* @type int|string|false $lastmodunix Last modified unix timestamp. May be a numeric string.
* False if not available.
* @type string|false $lastmod Last modified month (3 letters) and day (without leading 0), or
* false if not available.
* @type string|false $time Last modified time, or false if not available.
* @type string $type Type of resource. 'f' for file, 'd' for directory, 'l' for link.
* @type array|false $files If a directory and `$recursive` is true, contains another array of
* files. False if unable to list directory contents.
public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path ) . '/';
$pwd = ftp_pwd( $this->link );
if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
$list = ftp_rawlist( $this->link, '-a', false );
@ftp_chdir( $this->link, $pwd );
if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least).
foreach ( $list as $k => $v ) {
$entry = $this->parselisting( $v );
if ( '.' === $entry['name'] || '..' === $entry['name'] ) {
if ( ! $include_hidden && '.' === $entry['name'][0] ) {
if ( $limit_file && $entry['name'] !== $limit_file ) {
$dirlist[ $entry['name'] ] = $entry;
$path = trailingslashit( $path );
foreach ( (array) $dirlist as $struc ) {
if ( 'd' === $struc['type'] ) {
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
$struc['files'] = array();
$ret[ $struc['name'] ] = $struc;
public function __destruct() {
ftp_close( $this->link );