using ftpWebRequest with an error: the remote server returned error 530 not logged in
Asked Answered
V

5

8

I am trying to use the ftpWebRequest in c# my code is

// 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(); the error is: the remote server returned error 530 not logged in if I try to go in to a browser page and in the url I write ftp://192.168.20.10/ the brows page is asking me for a name and password, I put the same name and password and I see all the files and folders in the ftp folder.

Volvulus answered 27/4, 2012 at 14:5 Comment(0)
P
18

Shouldn't the line:

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

be:

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

or:

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

I have to believe this may be causing your issues because the \f is a form feed character.

Parma answered 7/5, 2012 at 13:4 Comment(0)
E
10

Faced the same issue, here's my solution:

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

Details can be found here

Hope it helps.

Ectomere answered 26/6, 2013 at 4:20 Comment(0)
V
7

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

Vitalis answered 13/11, 2012 at 10:33 Comment(1)
That Worked! ThanksMickeymicki
F
0

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

Fascia answered 24/8, 2017 at 10:42 Comment(1)
Don not post the same answer to several question. It is probably better then to mark them as duplicate of each other.Tether
W
0

If you assume anonymous logon do not set network credentials. this was the root of my problems.

Wanting answered 11/9, 2019 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.