FTP directory listing


Directory Browing with PHP.

PHP File upload progres bar.

krb5.h? what's that?

The LIST command

If you read the previous pages you know how to open a control connection to the server, login and follow it up by opening the data connection. This page looks at the actual directory list retrieval.

The result of the LIST command is a new line separate listing of entries in the given path. If you do not specify a path the the contents of the current working directory is listed. The code below sends the LIST command and collects the response.

	function dir_list($path="")
			if($path == '')
				$this->sock_write("LIST $path");
					$line = fgets($this->data_sock);
					$s .= $line;
					if($line =='')
		return $s;

While we can collect this listing and echo it out, that in itself isn't particularly usefull, we should convert it to a format that's more convinient to use. There is another usefull article on this site titled Directory Browsing with PHP shows how a directory listing can be parsed into an array.

In the next step we will integrate the code from that article with our FTP class. You might want to download the code for this page before we move on.

SourceForge.net Logo

FTP Applet

  Part 1   Introduction ,   Data Connection ,   Directory List ,   demo
  Part 2   Architecture ,   Downloading ,   Demo ,   Sessions
  Part 3   CWD ,   CDUP ,   Where am I? ,   Prune and Graft
  Part 4   Upload ,   Rename ,   Delete,   No operation