FTP :: CWD :: Change Working Directory.

New Articles

On Jabber.

PHP File upload progress bar.

What's a session anyway?

FTP Directory Management.

If you have read the first parts of of this article you have a web based FTP client on your hands that can browse a directory and retrieve files in it. However it's still incapable changing into other directories or creating new ones. We will put that right in this third part in the article by adding complete directory management support to our File Transfer Program.

There are four main commands in the RFC that deal with directories, there are CWD, MKD, RMD and CDUP. They deal with changing the working directory, making a new directory, removing an existing directory and changing over to the parent directory in that order. There is also the informational PWD command which tells us the Path to the Working Directory.

Our first victim is going to be the CWD command, for which the syntax is

 
 	CWD pathname 
 

And this is our source code to implement it, as you can see since we have built most of the infrastructure already we need just two lines of code.

	
	function CWD($path)
	{
		$this->sock_write("CWD $path");
		return check_reply("250");
	}

	

As you can see the implementation looks almost trivial, that's because all of the directory manipulation commands give their output on the control connection and we need not bother with openining and closing a data connection for each and every command. Thanks to this simplicity we can afford to go through all the commands first before sitting down for another demo. next step we will look at both the CDUP and the PWD commands.

 

Navigation
  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