How to move a file from one remote directory to another

Dec 2, 2011 at 5:38 PM

What would be the best way to go about moving a file from one remote directory to another?

We have a SQL backup file on a hosted site that we need to move to a different directory (on the same site).  Since the file is large, we would prefer to not have to save it locally and then uploading to the new directory.

Also, we did encounter a problem when executing the PutFile.  Any suggestions would be appreciated.

 

using (FtpConnection ftp2 = new FtpConnection(ftpHost, ftpUser, ftpPass))
                {
                    ftp2.Open(); 
                    ftp2.Login(); 

                    if (ftp2.DirectoryExists("/folder1/folder2/folder3/")) 
                    {
                        ftp2.SetLocalDirectory(@"C:\");

                        ftp2.SetCurrentDirectory("/folder1/folder2/"); 
                        ftp2.GetFile(newFileName, true);

                        ftp2.SetCurrentDirectory("/folder1/folder2/folder3/");
                        ftp2.PutFile(newFileName);
                    }
                    
                    ftp2.Close(); 
                }

Mar 13, 2014 at 8:04 PM
use ftp.RenameFile() with the new directory path in the filename as follows:
           ftp.RenameFile(file.Name, "/history/" + file.Name);  
it will move the file with the new name....