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

The topic How to use FTPS (introduction) describes the FTPS features of SSLFTPClient. This topic demonstrates the use of FTPS with server validation in the case where the server certificate's CommonName (CN) is the same as its address.

Firstly, the root certificate (the certificate of the CA that issued the certificate) must be loaded. Alternatively, the server certificate itself can be loaded. The PEM format is widely used, and loading a PEM certificate is shown below:

ftp.getRootCertificateStore().importPEMFile(certificateFile);

As in FTPS without server validation, connect() must then be called, followed by auth():

ftp.connect();
ftp.auth(SSLFTPClient.AUTH_TLS);

While the secure connection is being established the CommonName (CN) of the server certificate is checked against the hostname of the server. If this check fails, the connection will fail. Please refer to How to use FTPS (with server validation - part B) and How to use FTPS (with server validation - part C) for more details on this issue.