FTP远程服务器返回错误:(530)未登录 [英] FTP The remote server returned an error: (530) Not logged in

查看:857
本文介绍了FTP远程服务器返回错误:(530)未登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试解决这个问题超过4个小时,这让我发疯了.

I have been trying to solve this problem more than 4 hours, it is getting me crazy.

我创建了一个FTP,我想使用c#代码读取一些数据.

I created an FTP, and I wanna read some data using c# code.

当FTP没有用户名/密码访问权限时,一切正常.但是当我输入用户名和密码时,出现以下错误信息:远程服务器返回错误:(530)未登录.

when the FTP has no username/password access, everything works perfectly. but when I put username and password, i got this error message: The remote server returned an error: (530) Not logged in.

我尝试了所有关于stackoverflow和互联网的问题,例如:使用 .Normalize(),并使用 @username ,但我一直收到该错误.

I tried all the questions on stackoverflow and internet like: using .Normalize(), and using @username, but I keep getting that error.

这是我的代码:

foreach (string fileNameInFTP in directories)
                {
                    //                string fileNameInFTP2 = Path.GetFileNameWithoutExtension(fileNameInFTP);
                    if ((!haveWeAlreadyParsedThisFile(fileNameInFTP)) && (fileNameInFTP.Contains("CustsExport")) && (!fileNameInFTP.EndsWith("Empty.xml")) && (!fileNameInFTP.Contains("DelCustsExport")))
                    {
                        string file = FTPAddress + "/" + fileNameInFTP;
                        Console.WriteLine(file);
                        List<Customer> customersList =
                        (
                            from e in XDocument.Load(file).Root.Elements("cust")
                            select new Customer
                            {
                                MemeberID = (int)e.Attribute("memberid"),
                                CustomerID = (int)e.Attribute("custid"),
                                FirstName = (string)e.Attribute("fname"),
                                LastName = (string)e.Attribute("lname"),
                                ShowsNumber = (int)e.Attribute("count_noshow"),
                                VisitNumber = (int)e.Attribute("count_resos"),
                                Cancellation = (int)e.Attribute("count_cancel"),
                                MobileNumber = (string)e.Element("phone").Attribute("phonenumber")
                                /*Projects =
                                (
                                    from p in e.Elements("projects").Elements("project")
                                    select new Project
                                    {
                                        ProjectCode = (string)p.Element("code"),
                                        ProjectBudget = (int)p.Element("budget")
                                    }).ToArray()*/
                            }).ToList();

:请注意

,我能够访问FTP,因为 directories 变量是FTP中文件的列表,并且在调试代码时,我可以看到它个文件,但此行中出现异常:

:please note

that I am able to access the FTP because the directories variable is the list of the files in the FTP, and when I debug the code, I can see that it has the files, but the exception accurs in this line:

                    List<Customer> customersList =
                    (
                        from e in XDocument.Load(file).Root.Elements("cust")
                        select new Customer
                        {
                            MemeberID = (int)e.Attribute("memberid"),
                            CustomerID = (int)e.Attribute("custid"),
                            FirstName = (string)e.Attribute("fname"),
                            LastName = (string)e.Attribute("lname"),
                            ShowsNumber = (int)e.Attribute("count_noshow"),
                            VisitNumber = (int)e.Attribute("count_resos"),
                            Cancellation = (int)e.Attribute("count_cancel"),
                            MobileNumber = (string)e.Element("phone").Attribute("phonenumber")
                            /*Projects =
                            (
                                from p in e.Elements("projects").Elements("project")
                                select new Project
                                {
                                    ProjectCode = (string)p.Element("code"),
                                    ProjectBudget = (int)p.Element("budget")
                                }).ToArray()*/
                        }).ToList();

换句话说:我能够读取文件的名称,但不能读取文件的内容

推荐答案

您可以在FTP URL上提供用户名和密码.例如,如果要从 ftp://ftp.foo.com 下载/path/filename ,则可以对用户名和密码进行如下编码:

You can supply the user name and password on the FTP URL. For example, if you want to download /path/filename from ftp://ftp.foo.com, you can encode the user name and password like this:

ftp://username:password@ftp.foo.com/path/filename

您应该能够为要下载的文件构造这样的URL.然后将该URL传递给 XDocument.Load .

You should be able to construct such a URL for the file you're trying to download. Then pass that URL to XDocument.Load.

但是请注意,密码是以明文形式发送的(即未加密等).

Note, however, that the password is sent in the clear (i.e. no encryption, etc.).

有关更多信息,请参见 RFC 1738 的第3.2节.

See Section 3.2 of RFC 1738 for more info.

这篇关于FTP远程服务器返回错误:(530)未登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆