Rename Files

New Articles
J2ME and Nokia 6600.
PHP File upload progres bar.
The case of the missing errors.

FTP Rename files and folders

The renaming files on an FTP site is a two step process. We have already seen that upload, download and directory list are all two step processes as well. However rename is different from the others because it does not involve the use of a data connection as the other three. Both instructions are sent over the control connection.

As the first step we need to send the RNFR - Rename From command to the server. We should follow up with the RNTO - rename to command only if the first command is successfull. There will be situations where the first step is successfull but the second one is not.


  
  	function rnfr($filename)
	{
		sock_write("RNFR $filename");
		if(is_ok())
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	
	function rnto($filename)
	{
		sock_write("RNTO $filename");
		if(is_ok())
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
  

This pair of commands can be applied to both directories and files. On some servers it may be possible to use these commands to move from one folder to another by giving a full path name as input for the RNTO command. However it's not widely supported among servers or clients.



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