Skip to content

Automatic Connection

Robinicks edited this page Feb 20, 2020 · 24 revisions

API

  • AutoDetect() - Automatically discover working FTP connection settings and return those connection profiles. This method will try every possible connection type combination in a loop 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.

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

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.

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();

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. SysSslProtocols.None - Let the OS decide which TLS/SSL version to use
  2. SysSslProtocols.Tls12 - TLS 1.2 (TLS 1.3 is not yet stable in .NET Framework)
  3. SysSslProtocols.Tls11 - TLS 1.1
  4. SysSslProtocols.Tls - TLS 1.0
  5. SysSslProtocols.Ssl3 - SSL 3.0 (obsolete, need to use TLS instead)
  6. SysSslProtocols.Ssl2 - SSL 2.0 (obsolete, need to use TLS instead)
  7. SysSslProtocols.Default - Undefined/weird behaviour

Data Connection Type Preference:

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

Encoding Type Preference:

  1. Encoding.UTF8 - We prefer Unicode encoding as there will be no issues with file and folder names
  2. Encoding.ASCII - ASCII/ANSI is a fallback used for older servers
Clone this wiki locally