Getting “(553) File name not allowed” when renamin

2019-02-20 14:32发布

问题:

In my application, I have files in FTP server one directory and I move that file source to target path. In this process, when I move selected source file that source file will not show in the source path, it will show only in target path.

I tried this below code, but I am getting error:

string sourceurl = "ftp://ftp.com/Mainfoder/Folder1/subfolder/subsubfolder/"
string Targetpat =
    "ftp://ftp.com/Mainfoder/DownloadedFiles/"+subfolder+"/"+todaydatefolder+"/"+susubfolder;
Uri serverFile = new Uri(sourceurl + filename);
request = (FtpWebRequest)FtpWebRequest.Create(serverFile);
request.Method = WebRequestMethods.Ftp.Rename;
request.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
request.RenameTo = Targetpat+"/"+newfilename;//folders without filename
response = (FtpWebResponse)request.GetResponse();               
Stream ftpStream = response.GetResponseStream();    

An unhandled exception of type 'System.Net.WebException' occurred in System.dll Additional information: The remote server returned an error: (553) File name now allowed.

response = (FtpWebResponse)request.GetResponse(); //This line throwing the above exception   

request.RenameTo = newfilename: when I set only newfilename, it renames that source same file name only.

How can I move this file to another directory within in same FTP server?

Please can anyone tell me. Thank you

回答1:

As I wrote you already before:

request.RenameTo takes a path only.

So this is wrong:

string Targetpat =
    "ftp://ftp.com/Mainfoder/DownloadedFiles/"+subfolder+"/"+todaydatefolder+"/"+susubfolder;
request.RenameTo = Targetpat+"/"+newfilename;

It should be:

string Targetpat =
    "/Mainfoder/DownloadedFiles/"+subfolder+"/"+todaydatefolder+"/"+susubfolder;
request.RenameTo = Targetpat+"/"+newfilename;