7

I try to list file details using FtpWebRequest but very frequently it fails with a WebException and shows error 530 User not logged in.

How is this possible, that it works some of the time using the same credentials?

Excerpt from code:

        reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpuri));
        reqFTP.UseBinary = true;
        reqFTP.Credentials = new NetworkCredential(userName, password);
        string[] downloadFiles = new string[0];
            reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            WebResponse response = reqFTP.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            downloadFiles = reader.ReadToEnd().Replace("\r\n", "¤").Split('¤');
            reader.Close();
            response.Close();
2
  • I have had this exact problem. It seems to happen more often when I have already been connected to the server for a while, then I change directory and do a list.
    – Jonathan
    Feb 17, 2010 at 9:51
  • Your problem is similar to the bug the built in Windows Explorer FTP (ie: Internet Explorer integrated into Explorer.exe) where after navigating a directory it would "lose" your credentials and repeatedly ask you to login. I've never heard of this behavior when using dotnet, though. Apr 28, 2011 at 9:15

1 Answer 1

2

Try setting

reqFTP.KeepAlive = false;

and possibly if the above does not work

reqFTP.UsePassive = false;

I found that setting these to false reduced the occurrences of this error (which is generated by the FTP server) considerably.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.