0 votes
by (230 points)

Something news about the autodetection (active/passive ftp)?

related to an answer for: Autodetect Active/Passive FTP Clients
Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (144k points)

We have not added autodetection yet due to the following reasons:

  • FTP servers that only allow active mode and not passive mode became even rarer than they were in 2010. (We believe the major reason for this is the advent of FTP over TLS/SSL, which makes it impossible for content-aware firewalls to tweak the communication to make active mode FTP work.)
  • Autodetection is actually quite tricky. The only way to ensure that active or passive mode works is to actually try one mode first, followed by the other mode. In order to do this, you either have to download/upload a file or retrieve a directory listing. Downloading/uploading is something we would rather avoid, and listing a directory might be problematic in some scenarios as well.

So our current recommendation is to use the following simple-yet-reliable autodetection:

try
{
    ftp.GetNameList();
}
catch (FtpException ex1)
{
    ftp.Passive = !ftp.Passive;
    try
    {
        ftp.GetNameList();
    }
    catch (FtpException ex2)
    {
        throw new AggregateException("Unable to establish FTP data connection.", ex1, ex2);
    }
}
...