简体   繁体   中英

Getting “(553) File name not allowed” when renaming file on FTP server

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM