首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >远程服务器返回错误:(553)文件名不允许[C#] [FTP]

远程服务器返回错误:(553)文件名不允许[C#] [FTP]
EN

Stack Overflow用户
提问于 2019-04-23 01:52:32
回答 1查看 1.5K关注 0票数 3

我正在编写一个将文件从USB复制到FTP服务器的程序,这是代码的一部分:

代码语言:javascript
复制
        private const string ftp_url = @"ftp://an_ip_addrs/X";

        private static void Upload(string sourceDir)
        {
            using (WebClient client = new WebClient())
            {
                try
                {
                    client.Credentials = new NetworkCredential(ftp_username, ftp_psw);

                    foreach (var filename in Directory.GetFiles(sourceDir))
                    {
                        Console.WriteLine("Preparing to upload --> " + filename);

                        client.UploadFile(ftp_url, WebRequestMethods.Ftp.UploadFile, filename);
                        Console.WriteLine("File Uploaded!");
                    }
                } catch (Exception e)
                {
                    Console.WriteLine("Err FTP --> " + e);
                }
            }
        }

这是Preparing to upload的输出

代码语言:javascript
复制
Preparing to upload --> C:\Users\aimproxy\jn54comu\FASM - Copy (10).PDF

实际上,我从try catch block得到了这个错误

代码语言:javascript
复制
"Err FTP -->  System.Net.WebException: The remote server returned an error: (553) File name not allowed.
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
   at System.Net.WebClient.UploadFile(String address, String method, String fileName)
   at usb_backdoor_csharp.Program.Upload(String sourceDir) in C:\Users\aimproxy\Desktop\Program.cs:line 29

根据请求,这是ftp.exe的输出

代码语言:javascript
复制
Connected to 192.168.1.5.
220 Welcome to virtual FTP service.
503 USER expected.
User (192.168.1.5:(none)): upload
331 Password please.
230 User logged in.
ftp> dir
200 PORT 192.168.1.67:59392 OK
150 BINARY data connection established.
drwxrwxrwx   2 0        0        4096 Apr 22 18:07 X
226 Directory list has been submitted.
ftp: 135 bytes received in 0.02Seconds 7.50Kbytes/sec.
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55798734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档