Skip to content

Automatic Connection

Robin Rodricks edited this page Aug 29, 2021 · 24 revisions

API

  • AutoConnect() - Automatically discover working FTP connection settings and use those to connect to the server. This method will intelligently try certain combinations of connection settings until it finds a working combination. The connection types are tried in this order of preference.

  • AutoDetect() - Automatically discover working FTP connection settings and return those connection profiles. This method will intelligently try certain combinations of connection settings until it finds a working combination, and it will return the first found combination or all found combinations. The connection types are tried in this order of preference.

How do I auto-connect to an FTP or FTPS server?

Use this code:

FtpClient client = new FtpClient(hostname, username, password); // or set Host & Credentials
client.AutoConnect();

How do I auto-detect the correct connection settings?

Use this code:

FtpClient client = new FtpClient(hostname, username, password); // or set Host & Credentials
var profiles = client.AutoDetect();

// if any profiles are found, print the code to the console
if (profiles.Count > 0){
	var code = profiles[0].ToCode();
	Console.WriteLine(code);
}

Once you find a working connection profile, use the generated code to quickly connect to your FTP server.

In what order of preference does an auto connection follow?

Auto connection attempts to find working connection settings in this order of preference:

Protocol Preference:

  1. Explicit FTPS (TLS) - very common
  2. Plaintext FTP - very common
  3. Implicit FTPS (SSL) - outdated and very rare

FTPS Protocol Preference:

  1. None - Allows the operating system to choose the best protocol to use, and to block protocols that are not secure.
  2. Tls12 | Tls11 - TLS 1.2 or TLS 1.1 (TLS 1.3 is not yet stable in .NET Framework)
  3. Tls - TLS 1.0
  4. Default - Undefined/weird behaviour

Data Connection Type Preference:

  1. PASV - We prefer passive as its the most reliable
  2. EPSV - Enhanced passive is not as well supported on servers
  3. PORT - PORT is an older connection type
  4. EPRT - Enhanced PORT is not as well supported on servers
  5. PASVEX

Encoding Type Preference:

  1. UTF8 - We always use Unicode if it can be supported by the server
Clone this wiki locally