Skip to main content

FTP C# Error : “The remote server returned an error: (530) Not logged in ."

 

Recently working on a FTP solution using C# , i encountered an error The remote server returned an error: (530) Not logged in.”

The code i used was following:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp://xxxxxx/file.txt); 
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = new NetworkCredential(usernameVariable, passwordVariable);

What was more bewildering was if i modified the code to following, the solution was working fine. But this for obvious reasons is not an option as the username cannot be hardcoded

//works but implausible to use in realtime solutions
request.Credentials = new NetworkCredential("dmn/#gsgs", password);  

Some googling revealed that special charcters create issues in the NetworkCredential Object. Hence some playing around worked for me, and it works irrespective of wether i do a FTPWebRequest or WebRequest.

Solution:

Instantiate NetworkCredential object with three paramters (username, password, domain) and make sure to normalize the string variables while instantiating the NetworkCredential Object.

i.e:

//this works
request.Credentials = new NetworkCredential(usernameVariable.Normalize(),passwordVariable.Normalize(),domainVariable.Normalize());
 

Note: Normalize the string while instantiating the NetworkCredential object like above . The following doesnt work:

string usr = usernameVariable.Normalize()
string pwd= passwordVariable.Normalize()
string dom = domainVariable.Normalize()
request.Credentials = new NetworkCredential(usr,pwd,dom);  // wont work

 

Hope it helps !!

Comments

Popular posts from this blog

How to Add/Edit environment variables on Windows.

 1. Search and Open Environment variables 2. On the "System Properties" panel click Environment Variables 3. Double click on the required variable to edit/add new values.

Telecom Churn Case Study Upgrad - Kaggle Competition - Godwin Paul Notebook

Telecom Churn Case Study Upgrad Telecom Churn Case Study ¶ Overview ¶ In the telecom industry, customers are able to choose from multiple service providers and actively switch from one operator to another. In this highly competitive market, the telecommunications industry experiences an average of 15-25% annual churn rate. Given the fact that it costs 5-10 times more to acquire a new customer than to retain an existing one, customer retention has now become even more important than customer acquisition. For many incumbent operators, retaining high profitable customers is the number one business goal. Business Objective ¶ The objective is to reduce customer churn and improve customer retention in a highly competitive market. Retaining high profitable customers is the number one business goal Case Study Objective ¶ The goal is to build a machine learning model using customer-level data to identify customers at high risk of churn.