FTP 远程服务器返回错误:(530) 未登录

问题描述 投票:0回答:1

我创建了一个FTP,我想使用C#代码读取一些数据。当 FTP 没有用户名/密码访问权限时,一切正常。但是当我输入用户名和密码时,我得到

The remote server returned an error: (530) Not logged in

我尝试了 Stack Overflow 和互联网上的所有问题,例如使用

.Normalize()
和使用
@username
,但我不断收到该错误。

这是我的代码:

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中的文件列表,当我调试代码时,我可以看到它**有**文件,但是例外在这一行中:
                    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();

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

c# ftp
1个回答
0
投票

您可以在 FTP URL 上提供用户名和密码。例如,如果你想从

/path/filename
下载
ftp://ftp.foo.com
,你可以像这样编码用户名和密码:

ftp://username:[email protected]/path/filename

您应该能够为您尝试下载的文件构建这样的 URL。然后将该 URL 传递给

XDocument.Load

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

请参阅 RFC 1738 的第 3.2 节了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.