Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
Hi There,

I have developed one windows service in .net, It used to take files from FTP server to Local server. It looks files on ftp server after every 5 min and copies file from FTP to server. But it work fine for ten to fifteen hour after that it throws error continuously as below:".Error At Getlist():The operation has timed out."Please suggest me the modification.
Code for get list of file name below :
public string[] GetFileList()
         string[] downloadFiles;
         StringBuilder result = new StringBuilder();
         WebResponse response = null;
         StreamReader reader = null;
             FtpWebRequest reqFTP;
             reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("uri"));
             reqFTP.UseBinary = true;
             reqFTP.Credentials = new NetworkCredential("Abc", "Abc");
             reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
             reqFTP.Proxy = null;
             reqFTP.KeepAlive = false;
             reqFTP.UsePassive = false;
             response = reqFTP.GetResponse();
             reader = new StreamReader(response.GetResponseStream());
             string line = reader.ReadLine();
             while (line != null)
                 line = reader.ReadLine();
             // to remove the trailing '\n'
             result.Remove(result.ToString().LastIndexOf('\n'), 1);
             return result.ToString().Split('\n');
         catch (Exception ex)
             if (reader != null)
             if (response != null)
             downloadFiles = null;
             WriteLog("Error at GetFileList :>" + ex.Message);
             return downloadFiles;
Updated 11-Feb-20 21:49pm
Pheonyx 1-Aug-14 7:18am    
If you are connecting to an FTP server every 5 minutes, there is a chance the server could be blocking your connection after a period of time.

On which line is the "time out" occurring?
nira.parmar 11-Aug-14 7:19am    
At this line time out occuring.
SO please tell me what should have to do to check files are available on server or not?
gggustafson 11-Aug-14 13:41pm    
This is what is called a "long lived program". You might want to shutdown and restart the process every 10 hours. If that doesn't work, you might consider that something else on the local server might be interfering. If that is the case, you might consider rebooting the local server every ten hours.
nira.parmar 22-Aug-14 3:38am    
Please tell me how to avoid time out. it occurs after 10 to 15 hrs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900