.Net FtpWebRequest Sometimes Doesn't Work

I am trying to list file data using FtpWebRequest, but very often it fails using WebException and shows error 530 The user is not logged in.

How is it possible that it works for a while using the same credentials?

Code excerpt:

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(); 
+7
c # ftp ftpwebrequest
source share
1 answer

Try to install

 reqFTP.KeepAlive = false; 

and maybe if the above doesn't work

 reqFTP.UsePassive = false; 

I found that setting these values ​​to false significantly reduces the appearance of this error (which is created by the FTP server).

+1
source share

All Articles