0 votes
by (460 points)
edited

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
by (148k points)
edited

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

by
Kindly tell what we need to do to move empty directory
by (148k 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.
by
Thanks a lot :)
0 votes
by (460 points)
edited

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
by (58.9k points)
edited

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?

...