Prune and Graft with FTP

New Articles

On Jabber.

PHP File upload progres bar.

Howto make a unique ID in perl.

Pruning and Grafting directories

Don't worry you haven't accidentally strayed to a page on gardening. We are talking of creating new directories and removing existing one from an FTP server.

So far we have looked at changing the working directory and asking the FTP server what directory we are in (with the PWD command). In this step we will look into how we can create new directories on the server and remove unwanted entries. The commands that handle these functions are MKD and RMD and they both have similar syntax.


	
	RMD  pathname 
	MKD  pathname 
	

Being a simple old client our FTP class will not bother to check the validity of the pathname that's passed to it and we will not bother to check if the directory exists before we attempt to remove it instead we will rely on the error messages returned by the FTP server to tell us that something has gone wrong. If the directory exists but is not empty you will still see an error response.

	
	function mkd($path)
	{
		$this->sock_write("MKD $path");
		return $this->check_reply("257");
	}
	
	function rmd($path)
	{
		$this->sock_write("RMD $path");
		return $this->check_reply("250");
	}
	

The above snippet contains both the RMD and MKD functionality, as you can see the code looks quite trivial fully justifying our decision to create a web based FTP client from scratch without relying on any external libraries.

Now that all of our directory management code has clicked into place we will now look at another demonstration. You may recall that the last time you checked out the code in action the client was able to download files but not move into directories. The demo you are about to see builds on the earlier demo by adding the directory manipulation functions to it.


Though our client can delete directories we are yet to provide support for file deletion. It will be addressed in the next part in this series

host : ftp://
User:
password:


SourceForge.net Logo

FTP Applet

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