Reputation: 2299
Is this possible to rename a folder on a FTP Server using the FTP command ?
I know that there is a Rename command for file renaming, but can I use it for folder's name ?
Upvotes: 4
Views: 14256
Reputation: 435
i am using following code to copy all files and folder after the ftp login function
function ftp_sync ($dir)
{
global $conn_id;
if ($dir != ".")
{
if (ftp_chdir($conn_id, $dir) == false)
{
echo ("Change Dir Failed: $dir<BR>\r\n");
return;
}
if (!(is_dir($dir)))
mkdir($dir);
chdir ($dir);
}
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $file)
{
if ($file == '.' || $file == '..')
continue;
if (@ftp_chdir($conn_id, $file))
{
ftp_chdir ($conn_id, "..");
ftp_sync ($file);
}
else
ftp_get($conn_id, $file, $file, FTP_BINARY);
}
ftp_chdir ($conn_id, "..");
chdir ("..");
}
Upvotes: 1
Reputation: 9429
This probably depends on the FTP client you are using, and the FTP server you're connecting to. Can you specify them both?
Upvotes: 0
Reputation: 500227
AFAIK, the same commands (RNFR
/RNTO
) are used for renaming directories (folders) as are used for renaming files. Your issue may be that you do not have permissions to do what you're trying to do.
Upvotes: 7
Reputation: 4939
One way would be to create a temporary directory, move all files into it, drop the existing directory, create the directory you want and move all the files into the new directory. Finally, drop the temporary directory.
(Assuming that ftp rename doesn't work because the original folder isn't empty).
Upvotes: 0