0

I've created a simple windows service that checks a FTP folder every 20 seconds and copies any files to the computer locally.

In debug mode it works perfectly, however when I install the release using installutil I catch the following error when calling

 using (response = reqFTP.GetResponse())

FTP error...System.Net.WebException: The operation has timed out at System.Net.FtpWebRequest.SyncRequestCallback(Object obj) at System.Net.FtpWebRequest.RequestCallback(Object obj) at System.Net.CommandStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() at System.Net.ConnectionPool.Destroy(PooledStream pooledStream) at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse) at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) at System.Net.FtpWebRequest.GetResponse() at FileMan.Service1.GetFileList() in....

The full request is as follows;

 string[] downloadFiles;
            StringBuilder result = new StringBuilder();
            WebResponse response = null;
            StreamReader reader = null;
            textWrite.WriteLine("attempting to get file list" + DateTime.Now + Environment.NewLine, true);
            try
            {
                FtpWebRequest reqFTP;
                ServicePointManager.DefaultConnectionLimit = 100;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(downloadSrc));
                reqFTP.UseBinary = true;
                textWrite.WriteLine("requestFTP...Passed..." + DateTime.Now + Environment.NewLine, true);
                //reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
                reqFTP.Proxy = null;
                reqFTP.KeepAlive = true;
                reqFTP.UsePassive = false;
                reqFTP.Timeout = 8000;

                //////////STOPS HERE
                //response = reqFTP.GetResponse();
                using (response = reqFTP.GetResponse())
                {
                    // Do stuff
                    //...

                    reader = new StreamReader(response.GetResponseStream());
                    string line = reader.ReadLine();

                    while (line != null)
                    {
                        result.Append(line);
                        result.Append("\n");
                        line = reader.ReadLine();
                    }
                    result.Remove(result.ToString().LastIndexOf('\n'), 1);
                    return result.ToString().Split('\n');
                }
            }
            catch (Exception ex)
            {
                textWrite.WriteLine("FTP error..." + ex + "..." + DateTime.Now + Environment.NewLine, true);
                textWrite.Close();
                if (reader != null)
                {
                    reader.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
                downloadFiles = null;
                return downloadFiles;
            }

Are there any permissions i need to add? As this works in debug mode, the code itself is fine. I just needed to figure out what was blocking it

P.S. I'm using LocalSystem as the Account and im copying the release build directly to the c drive before installing it using installutil.

Jube
  • 184
  • 2
  • 15
  • 1
    Did your machine connect to the FTP server? Did some firewall block it? – Niyoko Nov 03 '16 at 01:57
  • It had no problem connecting to it in debug mode (running through vs 2015) but times out in release mode Edit: just tried with firewalls off (no luck) – Jube Nov 03 '16 at 02:01
  • edrgkjl;rajklsafkjlsfkdaj Just turned of network firewall and it worked.................. Ill add an exception to the firewall and answer this question when i get it stable – Jube Nov 03 '16 at 02:12
  • 1
    Possible duplicate of [FtpWebResponse, the operation timed out](http://stackoverflow.com/questions/17669990/ftpwebresponse-the-operation-timed-out) – Martin Prikryl Nov 03 '16 at 07:31
  • That answer didnt help me – Jube Nov 03 '16 at 07:53
  • Well, then you should have stated it in your question, instead of asking the same one again. – Martin Prikryl Nov 03 '16 at 08:23
  • Definitly not a duplicate. SyncRequestCallback timeout was also a firewall thing for me – Thomas Koelle Aug 25 '20 at 09:23

1 Answers1

1

By turning off public firewall the program worked! I just added the Service exe to the inbounds firewall rule and it worked Hope this helps anyone else who's having similar troubles

Jube
  • 184
  • 2
  • 15