How to use FTPS (with server validation - part B)

This topic continues from How to use FTPS (with server validation - part A).

Every certificate has a CommonName (CN) attribute. It is common for this attribute to be set to the host-name of the server. If, for example, the name of the server is the CN would be also. When the CN is not the same as the host-name then the SSLFTPStandardValidator will not successfully validate the server certificate, and the connection attempt will fail.

As it is not uncommon for the hostname to differ from the CN, the name to match to the CN can be explicitly supplied to the validator. A new instance must be created, as shown below:

ftp.setCustomValidator(new SSLFTPStandardValidator(commonName));

Here, a commonName variable holds the string to be matched to the CN of the server certificate.

See How to use FTPS (with server validation - part C) for details on how to ignore the CN completely.

Apart from this, configuration of the SSLFTPClient is the same as in Part A.