【问题标题】:FTP error: (553) File name not allowedFTP 错误:(553) 文件名不允许
【发布时间】:2014-04-22 14:16:36
【问题描述】:

我正在尝试 ftp 文件,但出现以下错误:

远程服务器返回错误:(553) 文件名不允许。在 System.Net.FtpWebRequest.SyncRequestCallback(Object obj) 在 System.Net.FtpWebRequest.RequestCallback(Object obj) 在 System.Net.CommandStream.Dispose(布尔处理)在 System.IO.Stream.Close() 在 System.IO.Stream.Dispose() 在 System.Net.ConnectionPool.Destroy(PooledStream pooledStream) 在 System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse) at System.Net.FtpWebRequest.FinishRequestStage(RequestStage 阶段)在 System.Net.FtpWebRequest.GetRequestStream()

此异常发生在下面我的 sn-p 中标记的以下行。

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 个其他文件,没有问题。

【问题讨论】:

    标签: c# .net ftp ftpwebrequest


    【解决方案1】:

    我遇到了同样的问题,但我自己解决了。此问题的主要原因有两个: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

    【讨论】:

      【解决方案2】:

      我认为你的问题出在:

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

      【讨论】:

      • 我会试一试,然后告诉你结果!!
      • String.Format(@"ftp://{0}{1}", destination.FTPSite, outputFile) 而不是 @"ftp://" + destination.FTPSite + outputFile
      • 我的意思是:两种字符串格式化变体的输出是一样的。这不可能改变程序的结果。
      • 我在几天内尝试了此更改,但仍然遇到同样的问题。还有其他想法吗?如果我无法通过 .NET 解决它,我将使用 Chilkat 重写它,它 id 100% 而不是这样做。
      • 我发现了问题,最终用户正在更改 ftp 站点路径...叹息
      猜你喜欢
      • 2012-03-14
      • 2019-09-11
      • 2017-04-29
      • 1970-01-01
      • 2011-04-27
      • 2013-06-08
      • 1970-01-01
      • 2017-07-22
      相关资源
      最近更新 更多