Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.9k views
in .NET FTP by (320 points)
I'm using edtFTPFree. I would like to detect that my FTP server is no longer connected as in it has either gone off line or the cable has become unplugged.
I was hoping that there would be some kind of event that I could trap if this happens but I was unable to find one.

My second choice was to run a polling loop and keep checking the IsConnected property. This didn't work because even after I removed power from my FTP device/disconnected the cable IsConnected still kept returning true.

My next choice was to run a polling loop and send out a command, such as get files. hoping that if the server wasn't there, then an exception would be thrown. This didn't work either. I sent the command but the code just seemed to go off into the woods.

Is is possible to do this using edtFTP/Free? How about with one of the libraries that are for purchase?

Or do I have to back away from the FTP side and essentially use windows WMI to create a plug and play handler for ethernet?

Thanks,
Ira Idelson

3 Answers

0 votes
by (51.6k points)
When TCP connections are idle, no data is sent through them, so there is no way to detect if it's no longer possible to send data through them without actually trying it. So, this is what you need to do. Try calling pwd periodically. This will throw an IOException if the connection has been closed. Is that what you tried? It should work. If it doesn't then please post your code.

And yes, the pro version has a keep-alive feature which will send a command periodically and trigger a Closed event if the connection fails.

- Hans (EnterpriseDT)
0 votes
by (320 points)
Hi Hans,

I originally tried sending a GetFiles command which caused the hang. After pouring through the forums I found a posting with an issue similar to mine. This suggested using the GetSystemType() command. I tried that and was able to use the Exception to determine that the connection had been lost.

I after making my connection I use BeginInvoke to start a new thread where I surround the GetSystemType() command with a try/catch block. In the catch handler I fire a custom ConncetionLost event which closes the connection.

BTW, what is the difference between Close() and Close(true) where the second one abruptly closes the connection? When would I want to use the normal close and when would I want to use the abrupt close?


Thanks,
Ira Idelson
0 votes
by (51.6k points)
Yes, using GetSystemType should be fine too.

Close() closes the connection 'nicely' by sending a QUIT command and waiting for a response, whereas Close(true) just kills the connection abruptly. From the client's point of view, there's not really any reason to be 'nice' and use Close(). Servers are written to be able to handle that since connections often drop out due to comms problems.

- Hans (EnterpriseDT)

Categories

...