Using ftpWebRequest with an error: the remote server responded with an error 530 failed to log in

I am trying to use ftpWebRequest in c # my code

// Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.168.20.10/file.txt"); request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("dev\ftp", "devftp"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(@"\file.txt"); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; request.UsePassive = true; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); response.Close(); 

and I get an error in request.GetRequestStream (); error: the remote server returned error 530 is not logged in if I try to enter the browser page and in the url, I will write ftp://192.168.20.10/ the browser page asks for my name and password, I find the same name and password, and I I see all the files and folders in the ftp folder.

+6
source share
4 answers

Do not follow the line:

 request.Credentials = new NetworkCredential("dev\ftp", "devftp"); 

to be:

 request.Credentials = new NetworkCredential("dev\\ftp", "devftp"); 

or:

 request.Credentials = new NetworkCredential(@"dev\ftp", "devftp"); 

I should assume that this can cause problems, because \ f is a form feed character.

+15
source

Faced with the same problem, here is my solution:

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

Details can be found here.

Hope this helps.

+7
source

I found out that when connecting via .NET / C # to an FTP server, some characters are not "valid". After setting the login credentials for letters and numbers only [a-Z0-9], he worked for the login.

+6
source

Just remove the double quote from your username or password because sometimes $ sign username or password causes a problem. Its useful to use a single quote every time.

0
source

Source: https://habr.com/ru/post/914342/


All Articles