FTP:将文件从一个目录移动到另一个目录。例外:350文件存在,准备好新名称

时间:2017-04-24 13:10:05

标签: c# ftp ftpwebrequest

上传文件(orig.txt)到FTP目录说Test / test4,然后上传im检查test4中是否存在该文件,如果是,则将该文件移动到存档文件夹然后上传文件到test4 Dir。
在移动到存档文件夹时我得到了这个例外。 “350文件存在,准备好换新名称。” 以下是代码

if (CheckFileExists("ftp://1.1.1.4:1//Test/test4/orig.txt") //separate method which returns boolean
{
   FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create("ftp://1.1.1.4:1//Test/test4/orig.txt")
   req.Method = WebRequestMethods.Ftp.Rename;
   req.Credentials = new NetworkCredential("user","pass");
   req.KeepAlive = true;
   req.Timeout = -1;
   // Code  ...if file exists in archive folder path then rename string fileName i.e example orig.txt to new_orig.txt
   //req.RenameTo = ".../"+ ArchiveFolderPath + "/"+ fileName ;
   req.RenameTo = ".../TestDirectory/Test2/test1/new_orig.txt"; 
   try
   {
     FtpWebResponse response = (FtpWebResponse)req.GetResponse();
     WriteToLogFile("Moved File to Archive Folder");
     response.Close();
   }
   catch (WebException ex)
   {
     FtpWebResponse response = (FtpWebResponse)ex.Response;
     WriteToLogFile("Status Code : "+response.StatusCode.ToString() + ",FTP Status Desc: " + response.StatusDescription);
     response.Close();
   }
}

// Actual Path of Archive Folder = "ftp://1.1.1.4:1//TestDirectory/Test2/test1/"
// File to be uploded ="ftp://1.1.1.4:1//Test/test4/"

我哪里错了?请帮忙

0 个答案:

没有答案