I created an FTP, and I want to read some data using C# code. When the FTP has no username/password access, everything works perfectly. But when I put username and password, I get The remote server returned an error: (530) Not logged in
.
I tried all the questions on Stack Overflow and the internet like using .Normalize()
, and using @username
, but I keep getting that error.
this is my code:
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();
Note:
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();
In other words: I am able to read the names of the files, but not the content of them.