FTP file Rename and Move

May 21 2012 12:18 PM

I cannot figure out how to copy a file from an FTP location to a second FTP location (same FTP server) after changing its name, then deleting the original in the first location.

 

Here is what I am trying…the file name is not changed nor moved.  Neither is the original file deleted.

        internal void RenameAndMoveFile(string fileName)
        {
            DateTime now = DateTime.Now;
            string nowStr = now.ToString("dd MMM yyyy HH.mm.ss");
            string folderPath = "ftp://ftp.myPath.com/IN/Backup/";
            string destFileName = folderPath +"ImportData_Imported" + nowStr + ".xml";
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(fileName);
            request.Credentials = new NetworkCredential("UserName", "passWord");
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.RenameTo = destFileName;
            FtpWebRequest newRequest = (FtpWebRequest)FtpWebRequest.Create(destFileName);
            newRequest.Credentials = new NetworkCredential("UserName", "passWord");
            newRequest.Method = WebRequestMethods.Ftp.UploadFile;
            request.Method = WebRequestMethods.Ftp.DeleteFile;
        }