我正在尝试ftp文件,但是我收到以下错误:
远程服务器返回错误:(553)不允许使用文件名。在 System.Net.FtpWebRequest.SyncRequestCallback(Object obj)at System.Net.FtpWebRequest.RequestCallback(Object obj)at System.Net.CommandStream.Dispose(布尔处理)at System.IO.Stream.Dispose()at的System.IO.Stream.Close() 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阶段)at 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网站上的以下位置: 发送/ republicservices /发票/
档案:Republic_20140421_230019.inv
此代码最初在VB.net中有效,但现在在c#版本中遇到问题。有什么想法吗?此代码每天还会上传大约6个其他文件而不会出现问题。
答案 0 :(得分:0)
我遇到了同样的问题但是我自己解决了。此问题的主要原因是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
答案 1 :(得分:-1)
我认为您的问题出在:
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));