問題描述
我需要 FTP 文件到目錄.在 .Net 中,我必須使用目標文件夾上的文件來創建連接,因此我使用 FTP 手動將 Blank.dat 放在服務器上.我檢查了訪問(ls -l),它是-rw-r--r--.但是當我嘗試連接到 FTP 文件夾時,我得到:遠程服務器返回錯誤:(553)文件名不允許"從服務器返回.我所做的研究表明,這可能源于權限問題,但正如我所說,我有權查看文件并可以從文件夾運行 ls .還有哪些其他原因可能導致此問題,有沒有辦法連接到文件夾而無需指定文件?
I need to FTP a file to a directory. In .Net I have to use a file on the destination folder to create a connection so I manually put Blank.dat on the server using FTP. I checked the access (ls -l) and it is -rw-r--r--. But when I attempt to connect to the FTP folder I get: "The remote server returned an error: (553) File name not allowed" back from the server. The research I have done says that this may arrise from a permissions issue but as I have said I have permissions to view the file and can run ls from the folder. What other reasons could cause this issue and is there a way to connect to the folder without having to specify a file?
byte[] buffer;
Stream reqStream;
FileStream stream;
FtpWebResponse response;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(string.Format("ftp://{0}/{1}", SRV, DIR)));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(UID, PASS);
request.UseBinary = true;
request.Timeout = 60000 * 2;
for (int fl = 0; fl < files.Length; fl++)
{
request.KeepAlive = (files.Length != fl);
stream = File.OpenRead(Path.Combine(dir, files[fl]));
reqStream = request.GetRequestStream();
buffer = new byte[4096 * 2];
int nRead = 0;
while ((nRead = stream.Read(buffer, 0, buffer.Length)) != 0)
{
reqStream.Write(buffer, 0, nRead);
}
stream.Close();
reqStream.Close();
response = (FtpWebResponse)request.GetResponse();
response.Close();
}
推薦答案
雖然回復一個舊帖子只是認為它可能對某人有所幫助.
Although replying to an old post just thought it might help someone.
當你創建你的 ftp url 時,確保你沒有包含該登錄的默認目錄.
When you create your ftp url make sure you are not including the default directory for that login.
例如,這是我指定的路徑,我得到了異常 553 FileName not allowed exception
for example this was the path which I was specifying and i was getting the exception 553 FileName not allowed exception
ftp://myftpip/gold/central_p2/inbound/article_list/jobs/abc.txt
我使用的登錄名具有默認目錄 gold/central_p2.so 提供的 url 變得無效,因為它試圖在默認目錄中找到整個路徑.我相應地修改了我的 url 字符串并且能夠擺脫例外.
The login which i used had the default directory gold/central_p2.so the supplied url became invalid as it was trying to locate the whole path in the default directory.I amended my url string accordingly and was able to get rid of the exception.
我修改后的網址看起來像
my amended url looked like
ftp://myftpip/inbound/article_list/jobs/abc.txt
謝謝,
薩布
這篇關于無法連接到 FTP:(553) 文件名不允許的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!