获取“(553)文件名不允许”在FTP服务器上重命名文件时 [英] Getting "(553) File name not allowed" when renaming file on FTP server
问题描述
在我的应用程序中,我在FTP服务器的一个目录中有文件,并将该文件源移动到目标路径。在这个过程中,当我移动选定的源文件时,源文件将不会显示在源路径中,它将只显示在目标路径中。
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();
类型为'System.Net.WebException'的未处理异常发生在System.dll
附加信息:远程服务器返回错误:(553)现在允许使用文件名。
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 code>:当我只设置
newfilename
时,它仅重命名该源文件名。
request.RenameTo = newfilename
: when I set only newfilename
, it renames that source same file name only.
我可以将此文件移动到同一FTP服务器中的另一个目录吗?
How can I move this file to another directory within in same FTP server?
请任何人都可以告诉我。谢谢
Please can anyone tell me. Thank you
推荐答案
由于我已经写过了:
request.RenameTo
需要一个
所以这是错误的:
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;
这篇关于获取“(553)文件名不允许”在FTP服务器上重命名文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!