Net_FTP::ls() – returns the listing of a directory in a specified way.


require_once 'Net/FTP.php';

mixed Net_FTP::ls ( string $dir = null , string $mode = NET_FTP_DIRS_FILES )


this function gives you a listing of either the files / directories / both or an unformated array (like the PHP function ftp_rawlist()).


  • string $dir = null - The directory to list. You can either use a relative or an absolute path. This optional parameter will be set to the current path.

  • int $mode = - A constant representing the nodes list (directories, files, both or a ram directory listing). This parameter is determined by the constants (see: Constants). This parameter is optional and will be set for listing directories and files structured in an array.

Return value

mixed - a directory listing in the form you determine on success, otherwise PEAR::Error.


Several errors may be returned by ls. The errornumber is unspecific (until now) and will not tell you anything about the errormessage. Possible errors are:

Possible PEAR_Error values
Error message Description Solution
Raw directory-list in wrong format. The format given by the server on PHP function ftp_rawlist()was wrong. Check if the directory you wanted to be listed is correct and you have access to listing it. Specify a correct directory path (eg. /my/file/path/, ../) and check (maybe change) the rights on it.
Could not get last-modification-date of '$file'. The last-modification date could not be determined by PHP. Reasons for this might be that your FTP-server does not support the used command or that you gave the function a non existent file as reference.
  • check the given file for existence
  • contact the FTP server's admin
Date-format failed on timestamp '$res'. The given format-string was not well formated. Check the documentation of the PHP function date().


This function can not be called statically.


Using ls()



returns the size in bytes of a file. (Previous) deletes a file or directory. (Next)
Last updated: Mon, 22 May 2017 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.