Title: WP_Filesystem_SSH2::dirlist
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Filesystem_SSH2::dirlist( string $path, bool $include_hidden = true, bool $recursive = false ): array|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#wp--skip-link--target)

Gets details for files in a directory or a specific file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#parameters)󠁿

 `$path`stringrequired

Path to directory or file.

`$include_hidden`booloptional

Whether to include details of hidden ("." prefixed) files.

Default:`true`

`$recursive`booloptional

Whether to recursively include file details in nested directories.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#return)󠁿

 array|false Array of arrays containing file information. False if unable to list
directory contents.

 * `...$0` array
 *  Array of file information. Note that some elements may not be available on all
   filesystems.
    - `name` string
    - Name of the file or directory.
    - `perms` string
    - *nix representation of permissions.
    - `permsn` string
    - Octal representation of permissions.
    - `number` false
    - File number. Always false in this context.
    - `owner` string|false
    - Owner name or ID, or false if not available.
    - `group` string|false
    - File permissions group, or false if not available.
    - `size` int|string|false
    - Size of file in bytes. May be a numeric string.
       False if not available.
    - `lastmodunix` int|string|false
    - Last modified unix timestamp. May be a numeric string.
       False if not available.
    - `lastmod` string|false
    - Last modified month (3 letters) and day (without leading 0), or false if not
      available.
    - `time` string|false
    - Last modified time, or false if not available.
    - `type` string
    - Type of resource. `'f'` for file, `'d'` for directory, `'l'` for link.
    - `files` array|false
    - If a directory and `$recursive` is true, contains another array of files. 
      False if unable to list directory contents.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#source)󠁿

    ```php
    public function dirlist( $path, $include_hidden = true, $recursive = false ) {
    	if ( $this->is_file( $path ) ) {
    		$limit_file = basename( $path );
    		$path       = dirname( $path );
    	} else {
    		$limit_file = false;
    	}

    	if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) {
    		return false;
    	}

    	$ret = array();
    	$dir = dir( $this->sftp_path( $path ) );

    	if ( ! $dir ) {
    		return false;
    	}

    	$path = trailingslashit( $path );

    	while ( false !== ( $entry = $dir->read() ) ) {
    		$struc         = array();
    		$struc['name'] = $entry;

    		if ( '.' === $struc['name'] || '..' === $struc['name'] ) {
    			continue; // Do not care about these folders.
    		}

    		if ( ! $include_hidden && '.' === $struc['name'][0] ) {
    			continue;
    		}

    		if ( $limit_file && $struc['name'] !== $limit_file ) {
    			continue;
    		}

    		$struc['perms']       = $this->gethchmod( $path . $entry );
    		$struc['permsn']      = $this->getnumchmodfromh( $struc['perms'] );
    		$struc['number']      = false;
    		$struc['owner']       = $this->owner( $path . $entry );
    		$struc['group']       = $this->group( $path . $entry );
    		$struc['size']        = $this->size( $path . $entry );
    		$struc['lastmodunix'] = $this->mtime( $path . $entry );
    		$struc['lastmod']     = gmdate( 'M j', $struc['lastmodunix'] );
    		$struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
    		$struc['type']        = $this->is_dir( $path . $entry ) ? 'd' : 'f';

    		if ( 'd' === $struc['type'] ) {
    			if ( $recursive ) {
    				$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
    			} else {
    				$struc['files'] = array();
    			}
    		}

    		$ret[ $struc['name'] ] = $struc;
    	}

    	$dir->close();
    	unset( $dir );

    	return $ret;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-filesystem-ssh2.php#L770)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-filesystem-ssh2.php#L770-L833)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Filesystem_SSH2::sftp_path()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the ssh2.sftp PHP stream wrapper path to open for the given file.

  | 
| [WP_Filesystem_SSH2::is_file()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_file/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if resource is a file.

  | 
| [WP_Filesystem_SSH2::is_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_dir/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if resource is a directory.

  | 
| [WP_Filesystem_SSH2::is_readable()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_readable/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if a file is readable.

  | 
| [WP_Filesystem_SSH2::size()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/size/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file size (in bytes).

  | 
| [WP_Filesystem_SSH2::mtime()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/mtime/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file modification time.

  | 
| [WP_Filesystem_SSH2::dirlist()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets details for files in a directory or a specific file.

  | 
| [WP_Filesystem_SSH2::owner()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/owner/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file owner.

  | 
| [WP_Filesystem_SSH2::group()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/group/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file’s group.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  |

[Show 5 more](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#)

| Used by | Description | 
| [WP_Filesystem_SSH2::dirlist()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets details for files in a directory or a specific file.

  | 
| [WP_Filesystem_SSH2::delete()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/delete/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Deletes a file or directory.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_ssh2%2Fdirlist%2F)
before being able to contribute a note or feedback.