How to move a directory from path to another path in Ftp

0 votes
asked Apr 3, 2012 by srinu (460 points)
edited Apr 4, 2012

Hi,

I want to move a directory form one location to another location with in ftp.

for example :

remote source path : /g:/TEST/abc remote destination path : /g:/BackUp/abc

how can i do this?

Thanks in advance

Applies to: Rebex FTP/SSL, Rebex SFTP

3 Answers

0 votes
answered Apr 3, 2012 by Lukas Pokorny (112,470 points)
edited Apr 3, 2012

Try calling ftp.Rename("/g:/TEST/abc", "/g:/BackUp/abc") (where 'ftp' is an instance of Ftp object), that should work.

commented 13 hours ago by ArpS (100 points)
Kindly tell what we need to do to move empty directory
commented 13 hours ago by Lukas Pokorny (112,470 points)
Empty directory at an FTP server can be moved in the same way as a non-empty directory - using Ftp object's Rename method.

Alternatively, in case the FTP server doesn't allow this, you could simply delete the directory and create a directory with the same name at the desired location.
commented 13 hours ago by ArpS (100 points)
Thanks a lot :)
0 votes
answered Apr 4, 2012 by srinu (460 points)
edited Apr 4, 2012

Hi Lukas,

Thanks for your replay. I write code for moving ftp folder, like :

    private void MoveFtpFolder("TEST/040312", "BACKUP")
    {
        try
        {
            string strFtpCurrentDirectory = string.Empty;
            string strNewFtpDir = string.Empty;
            bool blFtpDirExists;

            ftp.Connect(strFtpIp, iFtpPort);
            ftp.Login(strFtpUsrname, strFtpPwd);

            ftp.ChangeDirectory("");
            strFtpCurrentDirectory = ftp.GetCurrentDirectory();
            blFtpDirExists = ftp.DirectoryExists(strFtpBackupDir);

            if (blFtpDirExists == true)
            {
                //ftp.ChangeDirectory("..");
                //strFtpCurrentDir = ftp.GetCurrentDirectory();
                ftp.Rename(strFtpCurrentDir, strFtpBackupDir);
            }
            else
            {
                strNewFtpDir = ftp.CreateDirectory(strFtpBackupDir);
                //ftp.ChangeDirectory("..");
                //strFtpCurrentDir = ftp.GetCurrentDirectory();
                ftp.Rename(strFtpCurrentDir, strNewFtpDir);
            }
            ftp.Disconnect();
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex);
        }
    }

and i am getting exception like :

Rebex.Net.FtpException: /g:/srinu/BACKUP: Unable to rename file or directory (553). at Rebex.Net.Ftp.1SAJuN(Int32 , Boolean ) at Rebex.Net.Ftp.1SAJuN(Int32 ) at Rebex.Net.Ftp.Rename(String fromPath, String toPath) at UploadFiles.frmUpload.MoveFtpFolder(String strFtpCurrentDir, String strFtpBackupDir)

help me to resolve this issue.

Thanks Srinu

0 votes
answered Apr 4, 2012 by Tomas Knopp (58,890 points)
edited Apr 4, 2012

Hello, the FTP server code response 553 suggests that you are trying to rename the directory to an illegal name.(See the RFC.) It means that there is some restriction on file names on your FTP server and you were breaking it. Were there any special characters in the new directory name?

...