PWD - Print Working Directory.

New Articles
Installing the mysqli extension.
PHP File upload progress bar.
Is FTP secure?.


If you have looked at the previous page you know already that the CWD command can be used as a substitute to the CDUP command. CWD .. is for all practicle purposes the same as CDUP on most implementation. CDUP is however still a part of the RFC and since the code to implement it only a couple of lines let's implement it anyway.

	function CDUP()
		return is_ok();


At this point it's worth mentioning that the RFC that describes the File Tranfer Protocol contains lots of functionality that is not found in commonly available servers. So we will not make any attempt to implement those commands in our client. If we did we would be hard pressed to find an FTP server to test it against.

Where am I? use PWD to find out

Unlike CDUP the PWD command can be quite usefull since it tells us the Path to the Current working directory. While our application should be capable of remembering this information on most intances it's not always convinient to do so.

As previous page the responses to the directory management commands are returned over the control connection and we do not need to establish a data connection to execute PWD (Print Working Directory). We still need to extract the path name from the response where it's mixed with the status code (257).

	function pwd()
			$parts = split(" ",$this->message);
			return preg_replace('/\"/',"",$parts[1]);
		return "";

The path that's returned should be enclosed in quotes, but we should be prepared to recieve this data unquoted as well, which is what we have done with the code above.

We will look at howto create new directories and remove exisiting ones in the next step 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
Copyright © Raditha Dissanayake 2013