简体   繁体   English

FTP错误:(553)不允许使用文件名

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

I am trying to ftp a file but i get the following error: 我正在尝试通过ftp传输文件,但出现以下错误:

The remote server returned an error: (553) File name not allowed. 远程服务器返回错误:(553)不允许使用文件名。 at System.Net.FtpWebRequest.SyncRequestCallback(Object obj) at System.Net.FtpWebRequest.RequestCallback(Object obj) at System.Net.CommandStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() at System.Net.ConnectionPool.Destroy(PooledStream pooledStream) at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse) at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) at System.Net.FtpWebRequest.GetRequestStream() 在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()

This exception occurs at the following line marked in my snippet below. 此异常发生在下面我的代码段中标记的以下行。

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();

It's trying to send to the following location on the ftp site: send/republicservices/invoice/ 它正在尝试发送到ftp站点上的以下位置:send / republicservices / invoice /

File: Republic_20140421_230019.inv 档案:Republic_20140421_230019.inv

This code originally worked in VB.net but now am getting issues in the c# version. 该代码最初在VB.net中有效,但现在在c#版本中出现问题。 Any ideas why? 有什么想法吗? This code also uploads about 6 other files daily without issue. 该代码还每天上传约6个其他文件,而没有任何问题。

I came faced the same problem however I solved it myself. 我遇到了同样的问题,但是我自己解决了。 The main 2 reasons of this problem are 1. Permission problem (rare) happens when you don't have permission to read/write to that file and 2. Error in path (common) happens when your ftp path is wrong. 出现此问题的主要原因有两个:1.权限问题(罕见)是在您没有对该文件的读/写权限时发生的; 2.路径错误(常见)是在ftp路径错误时发生的。 Without seeing your path it is impossible to say what's wrong but one must remember the things 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 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

I think your problem is at: 我认为您的问题出在:

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

Try this: 尝试这个:

    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