开发者

Is it possible to rename a FTP Folder using FTP commands?

Is this possible to rename a folder on a FTP Server using the FTP command ?

I know that there is a Rename co开发者_如何转开发mmand for file renaming, but can I use it for folder's name ?


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.


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 (".."); 
} 


Rename should work:

rename <dirname> <newdirname>


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).


This probably depends on the FTP client you are using, and the FTP server you're connecting to. Can you specify them both?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜