java代码ftp重命名未生效,获取“(553)文件名不允许”在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();

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

解决方案

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值