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

时间:2023-03-31
本文介绍了无法连接到 FTP:(553) 文件名不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I need to FTP a file to a directory. In .Net I have to use a file on the destination folder to create a connection so I manually put Blank.dat on the server using FTP. I checked the access (ls -l) and it is -rw-r--r--. But when I attempt to connect to the FTP folder I get: "The remote server returned an error: (553) File name not allowed" back from the server. The research I have done says that this may arrise from a permissions issue but as I have said I have permissions to view the file and can run ls from the folder. What other reasons could cause this issue and is there a way to connect to the folder without having to specify a file?

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

推荐答案

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

Although replying to an old post just thought it might help someone.

当你创建你的 ftp url 时,确保你没有包含该登录的默认目录.

When you create your ftp url make sure you are not including the default directory for that login.

例如,这是我指定的路径,我得到了异常 553 FileName not allowed exception

for example this was the path which I was specifying and i was getting the exception 553 FileName not allowed exception

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

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

The login which i used had the default directory gold/central_p2.so the supplied url became invalid as it was trying to locate the whole path in the default directory.I amended my url string accordingly and was able to get rid of the exception.

我修改后的网址看起来像

my amended url looked like

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

谢谢,

萨布

这篇关于无法连接到 FTP:(553) 文件名不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 C# 中从 FTP 读取文件到内存 下一篇:使用 VB.NET 将文件上传到 FTP 站点

相关文章