Autodetect Active/Passive FTP Clients

0 votes
asked Mar 30, 2010 by Will (140 points)
edited Mar 30, 2011

Is it possible to autodetect active or passive mode on the connected ftp client. If so, how?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Mar 30, 2010 by Martin Vobr (12,940 points)
edited Mar 30, 2010

Finding whether the server allows passive or active mode is a bit tricky.

To detect whether passive mode is possible, we have to improvise a bit. One possible way to do this with Rebex FTP:

  1. Make sure passive mode is enabled
  2. Lower the timeout from the default value of 60 seconds to something like 5 (or even leave it at 60 if detection speed is not an issue for you)
  3. Initiate a TransferProgress event handler
  4. Try calling GetList or GetNameList (preferably on a folder with few files) 4.
    • If the event handler is called at least once with state of FtpTransferState.Downloading, consider passive mode possible
    • If you get an FtpException with the Status set to Timeout, consider passive mode not impossible
    • If you get an FtpException with the Status set to ConnectFailure, consider passive mode not impossible
    • If you get other result, another error occured

Anyway, this seems rather complicated, so I added it into our list of possible future enhancements.

Vote the question up if it's important to you.

...