Discuss (FTP), (FTP on .NET CF) and (FTPS, SFTP and SCP).
no avatar
User

dlangell

Posts

20

Joined

Tue Jun 20, 2006 11:25 pm

How to cancel a connection attempt?

by dlangell » Wed May 21, 2014 4:44 am

What is the cleanest and most reliable way to cancel a connection attempt using the SecureFTPConnection that is taking a long time? I have tried calling Connect on a separate thread, and then calling Close(True) from the main thread if the user hits my Cancel button. Sometimes this works if the server is up and there are just problems negotiating with it. But if the server is not even accessible, it will wait the full timeout value before the Connect method finally returns and my worker thread finishes. I have tried the asynchronous BeginConnect and then calling AbortAsynchronous, but can't seem to get that working either. Is AbortAsynchronous only for transfers? What is the generally accepted way to cleanly stop a connection and have all underlying sockets immediately destroyed and disposed of?
no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

Re: How to cancel a connection attempt?

by support2 » Wed May 21, 2014 10:47 am

AbortAsynchronous is for canceling transfers. Have you tried using BeginConnect and then Close(True) if cancel is chosen?
no avatar
User

dlangell

Posts

20

Joined

Tue Jun 20, 2006 11:25 pm

by dlangell » Thu May 22, 2014 12:14 am

no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

by support2 » Thu May 22, 2014 12:27 pm

no avatar
User

dlangell

Posts

20

Joined

Tue Jun 20, 2006 11:25 pm

by dlangell » Fri May 23, 2014 12:15 am

This is not what I'm seeing (edtFTPnetPRO 8.5.0.20). Just for kicks, I called Close(True) and then called Close() directly afterwards 4-5 times. No exceptions were raised.

Again, the real issue is if I call Close(True) on a connection attempt to a server that IS NOT available (i.e. unplugged, powered off, disconnected from the network, etc.) In the code example listed previously, after calling Close(True) in this situation, if I were to be a good boy and call myFTP.Dispose as the very next line, the call to Dispose will block until the connection timeout actually expires, even though I just forced the close. I also see this if I immediately try to remove a handler as part of my cleanup. (All of this happens even if I DO NOT make a second call to Close().

If using the synchronous methods instead (by calling Connect on a worker thread and calling Close(True) on the parent thread), a subsequent call to Dispose will not block, but if I then Join the worker thread until it finishes, the join will block until the connection timeout expires, even though I tried to force the close from the parent. Right now I'm just forcing the worker thread to abort if it doesn't finish within a few seconds after trying to close the connection (which I'm not a fan of doing since it's not as clean).

I just renewed my support and upgraded to the latest version last week. Should I open an official support ticket instead of working through the forums?
no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

by support2 » Fri May 23, 2014 8:06 am


Who is online

Users browsing this forum: No registered users and 32 guests

Powered by phpBB ® | phpBB3 Style by KomiDesign
cron