0 votes
by (140 points)
edited

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
by (13.3k points)
edited

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.

...