I'm having trouble determining when my connection has been closed by the ftp server.

Here's the test that I am doing (all on my local network):

  1. Start FTP server on machine A (Serv-U)
  2. Connect to server with machine B
  3. Manually close the connection using Serv-U
  4. Call CheckConnectionState to see if the connection is still good
  5. CheckConnectionState doesn't throw any exception and now I am in an invalid state

Am I misunderstanding what CheckConnectionState is supposed to do?

asked 27 May '11, 16:52

John%20Hancock's gravatar image

John Hancock
251
accept rate: 0%


Ftp object's CheckConnectionState method only throws an exception if the connection is already known to have ended when the method is called. If the client machine is not yet aware that the connection has been lost, the method will return without raising an exception.

The only reliable way to determine whether the connection is still active is to send a command over it - if the connection has already been lost, it won't be possible to transmit the command to the server and the connection will be acknowledged as disconnected. In case of FTP, the KeepAlive or GetCurrentDirectory methods can be used for this purpose.

This said, it is a bit strange that CheckConnectionState can't detect a manually closed connection in this case. That kind of action should gracefully close the connection, making the client aware of it immediately, causing the CheckConnectionState method to fail. We will try to reproduce this problem ourselves. Until then, using one of the methods that actually send some command (see above) is recommended.

link

answered 30 May '11, 12:19

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×152
×22
×20

Asked: 27 May '11, 16:52

Seen: 696 times

Last updated: 30 May '11, 12:19