无法连接到FTP:(553)不允许使用文件名

我需要将文件FTP到目录。 在.Net中,我必须使用目标文件夹上的文件来创建连接,因此我使用FTP手动将Blank.dat放在服务器上。 我检查了访问权限(ls -l),它是-rw-r – r–。 但是当我尝试连接到FTP文件夹时,我得到:“远程服务器返回错误:(553)文件名不允许”从服务器返回。 我所做的研究表明,这可能来自权限问题,但正如我所说,我有权查看该文件,并可以从该文件夹运行ls。 还有什么其他原因可能导致此问题,是否有办法连接到该文件夹​​而无需指定文件?

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

虽然回复旧帖只是认为它可能对某人有所帮助。

创建ftp url时,请确保不包含该登录的默认目录。

例如,这是我指定的路径,我得到exception553 FileName不允许exception

 ftp://myftpip/gold/central_p2/inbound/article_list/jobs/abc.txt 

我使用的登录有默认目录gold / central_p2.so提供的url变得无效,因为它试图找到默认目录中的整个路径。我相应地修改了我的url字符串,并且能够摆脱exception。

我修改过的url看起来像

 ftp://myftpip/inbound/article_list/jobs/abc.txt 

谢谢,

SAB

这可能有助于Linux FTP服务器。

因此,不像IIS的Linux FTP服务器没有通用的FTP根目录。 相反,当您使用某些用户的凭据登录到FTP服务器时,将使用此用户的根目录。 因此,FTP目录层次结构从/ root /为root用户启动,从/ home / username为其他用户启动。

因此,如果您需要查询与用户帐户主目录无关的文件,但相对于文件系统根目录,请添加额外/后服务器名称。 生成的URL将如下所示:

 ftp://servername.net//var/lalala 

你必须小心名称和路径:

  string FTP_Server = @"ftp://ftp.computersoft.com//JohnSmith/"; string myFile="text1.txt"; string myDir=@"D:/Texts/Temp/"; 

如果你发送到http://ftp.computersoft.com/JohnSmith文件caled text1.txt位于d:/ texts / temp

然后

  FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTP_Server+myFile); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(FTP_User, FTP_Password); StreamReader sourceStream = new StreamReader(TempDir+myFile); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); 

注意,在某一刻你用作目的地

ftp://ftp.computersoft.com//JohnSmith/text1.txt

它不仅包含目录,还包含FTP服务器上的新文件名(通常可以与硬盘上的文件名不同)

在其他地方你用作来源

d:/Texts/Temp/text1.txt

您的目录有访问限制。
删除您的目录,然后使用以下代码重新创建:

 //create folder FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://mpy1.vvs.ir/Subs/sub2"); request.Method = WebRequestMethods.Ftp.MakeDirectory; request.Credentials = new NetworkCredential(username, password); request.UsePassive = true; request.UseBinary = true; request.KeepAlive = true ; using (var resp = (FtpWebResponse)request.GetResponse()) { } 

我曾经看过类似的东西,事实certificate我正在尝试连接到使用Active Directory保护的内部iis ftp服务器。

在我的网络凭据中,我使用的是新的NetworkCredential(@“domain \ user”,“password”); 那是失败的。 切换到新的NetworkCredential(“用户”,“密码”,“域”); 为我工作。

我希望这对某人有帮助

如果您使用的是LINUX服务器,请替换您的请求路径

 FtpWebRequest req= (FtpWebRequest)WebRequest.Create(@"ftp://yourdomain.com//yourpath/" + filename); 

 FtpWebRequest req= (FtpWebRequest)WebRequest.Create(@"ftp://yourdomain.com//public_html/folderpath/" + filename); 

文件夹路径是您在服务器中看到的方式(例如:cpanel)

虽然这是一篇较老的post,但我认为分享我的经验会很好。 我遇到了同样的问题但是我自己解决了。 这个问题的主要原因是路径错误(如果你的权限是正确的)当你的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

此错误的另一个原因可能是FTP服务器区分大小写。 这让我好好理解。

当我尝试以编程方式写入FTP站点的根目录时,我遇到了这个问题。 当我手动重复操作时,FTP会自动将我重新路由到子目录并完成写操作。 然后我更改了我的代码,使目标文件名前缀为子目录,操作成功。