繁体   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