1

So i have a service that i created that checks in with a server every x mins and receives a reply from it. The reply is either a sleep or command. receiving a scan command the service packs up and Tars a load of files and sends them off to the server. During Debug mode my app runs perfectly fine. I can step through the code and everything is being triggered as it should and the communication between client and server is perfectly fine.

However. Upon deployment of my service, it will crash upon receiving a scan command. I have looked at the windows Event Viewer and found this:

Application: Client.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info:
System.Net.WebException Stack: at
System.Net.FtpWebRequest.GetRequestStream() at
tcpClient.ftpClass.upload(System.String, System.String) at
Client.Service1.checkInCycle(System.String) at
Client.Service1.Callback(System.Object) at
System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object) at
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.TimerQueueTimer.CallCallback() at
System.Threading.TimerQueueTimer.Fire() at
System.Threading.TimerQueue.FireNextTimers() at
System.Threading.TimerQueue.AppDomainTimerCallback() 

The only possible point of failure i can think of in FTPWebRequest is the timeoutVal, but i have changed this to infinite using:

request.Timeout = -1;

So any ideas as to why this is happening ?

2 Answers 2

1

The only possible point of failure i can think of in FTPWebRequest is the timeoutVal

According to msdn System.Net.FtpWebRequest.GetRequestStream() can throw these exceptions:

  • InvalidOperationException
  • WebException
  • ProtocolViolationException.

Exception info you provided explicitly states that you've encountered WebException:

Exception Info: System.Net.WebException

According to msdn article I mentioned earlier that happens when

A connection to the FTP server could not be established.

Possible causes that you should check:

  • FTP server is offline or it's not available for access
  • FTP host and/or port are/is not correct.
  • FTP user credentials are required and either not provided or are incorrect.

Considering that you debug it without any problems and you've encountered it only after deployment, I think that your FTP server can be unreacheable from the environment where you deployed your service to.

2
  • Well how do i go about making it available to the environment i installed the service to?
    – amartin94
    Commented Sep 23, 2015 at 7:41
  • There are a lot of reasons why it can't be available. FTP ports that used by your servers are not allowed to be used in your environment(I've encountered this situation myself). Host itself is unreacheable(maybe you debugged your service on single host or LAN with ftp server and now they are "far" away and can't reach each other). Make sure that you could connect to your ftp server from your environment. Try to do it with some ftp-client app. If you can't then try to ping your ftp host from your service host. If you can reach it that it's likely ports issues. Commented Sep 23, 2015 at 7:48
0

Adding to what CodingFeles has said:

Should probably point out that this was a stupid mistake caused by nothing less than 10 hours of programming till 9am.... Ie. I was braindead at this point and introduced the error without realizing it:

The error was introduced because for some stupid reason, i accidentally commented out the network credentials for the FTP procedures and thats where everything stemmed from.

not saying that this will be your solution if you are also facing this issue.. But make sure you have the correct network credentials for the server and they are actually being passed through:

request.Credentials = new NetworkCredential("user", "pass");   

Your Answer

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

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