簡體   English   中英

FTP錯誤:(553)不允許使用文件名

[英]FTP error: (553) File name not allowed

我正在嘗試通過ftp傳輸文件,但出現以下錯誤:

遠程服務器返回錯誤:(553)不允許使用文件名。 在System.Net.FtpWebRequest.SyncRequestCallback(Object obj)在System.Net.CommandStream.Dispose(布爾處置)在System.IO.Stream.Close()在System.Net。 System.Net.ConnectionPool.PutConnection(PooledStream pooledStream)的System.Net.ConnectionPool.Destroy(PooledStream pooledStream)的System.Net.FtpWebRequest.FinishRequestStage(RequestStage階段的Object.owningObject,Int32 creationTimeout,Boolean可以重用) ),位於System.Net.FtpWebRequest.GetRequestStream()

此異常發生在下面我的代碼段中標記的以下行。

System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create("ftp://" + destination.FTPSite + outputFile);
clsRequest.Credentials = new System.Net.NetworkCredential(destination.FTPUserName, destination.FTPPassword);
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
clsRequest.Timeout = Properties.Settings.Default.FtpTimeOut;

// read in file...
byte[] bFile = System.IO.File.ReadAllBytes(localFile);

// upload file...
System.IO.Stream clsStream = clsRequest.GetRequestStream(); <<----
clsStream.Write(bFile, 0, bFile.Length);
clsStream.Close();
clsStream.Dispose();

它正在嘗試發送到ftp站點上的以下位置:send / republicservices / invoice /

檔案:Republic_20140421_230019.inv

該代碼最初在VB.net中有效,但現在在c#版本中出現問題。 有什么想法嗎? 該代碼還每天上傳約6個其他文件,而沒有任何問題。

我遇到了同樣的問題,但是我自己解決了。 出現此問題的主要原因有兩個:1.權限問題(罕見)是在您沒有對該文件的讀/寫權限時發生的; 2.路徑錯誤(常見)是在ftp路徑錯誤時發生的。 沒有看到自己的路,就不可能說出問題了,但是必須記住這些事情a. Unlike browser FTP doesn't accept some special characters like ~ b. If you have several user accounts under same IP, do not include username or the word "home" in path c. Don't forget to include "public_html" in the path (normally you need to access the contents of public_html only) otherwise you may end up in a bottomless pit a. Unlike browser FTP doesn't accept some special characters like ~ b. If you have several user accounts under same IP, do not include username or the word "home" in path c. Don't forget to include "public_html" in the path (normally you need to access the contents of public_html only) otherwise you may end up in a bottomless pit

我認為您的問題出在:

System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create("ftp://" + destination.FTPSite + outputFile);

嘗試這個:

    System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(String.Format(@"ftp://{0}{1}", destination.FTPSite, outputFile));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM