获取“(553)文件名不允许"在 FTP 服务器上重命名文件时 [英] Getting "(553) File name not allowed" when renaming file on FTP server

查看:66
本文介绍了获取“(553)文件名不允许"在 FTP 服务器上重命名文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在 FTP 服务器的一个目录中有文件,我将该文件源移动到目标路径.在这个过程中,当我移动选定的源文件时,源文件不会显示在源路径中,它只会显示在目标路径中.

我尝试了以下代码,但出现错误:

string sourceurl = "ftp://ftp.com/Mainfoder/Folder1/subfolder/subsubfolder/"字符串 Targetpat ="ftp://ftp.com/Mainfoder/DownloadedFiles/"+subfolder+"/"+todaydatefolder+"/"+susubfolder;Uri serverFile = new Uri(sourceurl + 文件名);请求 = (FtpWebRequest)FtpWebRequest.Create(serverFile);request.Method = WebRequestMethods.Ftp.Rename;request.Credentials = new NetworkCredential(ftpUserID, ftpPassword);request.RenameTo = Targetpat+"/"+newfilename;//没有文件名的文件夹响应 = (FtpWebResponse)request.GetResponse();流 ftpStream = response.GetResponseStream();

<块引用>

System.dll 中出现System.Net.WebException"类型的未处理异常附加信息:远程服务器返回错误:(553) 文件名现在允许.

response = (FtpWebResponse)request.GetResponse();//这行抛出了上面的异常

request.RenameTo = newfilename:当我只设置 newfilename 时,它只重命名该源相同的文件名.

如何将此文件移动到同一 FTP 服务器中的另一个目录?

谁能告诉我.谢谢你

解决方案

作为 我之前已经给你写过:

<块引用>

request.RenameTo 仅采用路径.

所以这是错误的:

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

应该是:

字符串 Targetpat ="/Mainfoder/DownloadedFiles/"+subfolder+"/"+todaydatefolder+"/"+susubfolder;request.RenameTo = Targetpat+"/"+newfilename;

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;

这篇关于获取“(553)文件名不允许"在 FTP 服务器上重命名文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆