問題描述
在我的應用程序中,我在 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 服務器上重命名文件時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!