C# – using ftpWebRequest with an error: the remote server returned error 530 not logged in


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("");
            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());
            request.ContentLength = fileContents.Length;
            request.UsePassive = true;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);


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
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.

Best Solution

Shouldn't the line:

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


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


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.

Related Question