PHP Requires Chilkat v11.0.0+
Chilkat2 PHP
FTP Connect, Examine Server Certificate, and then Authenticate
See more FTP Examples
Demonstrates how to connect to an FTP server, examine the server's SSL/TLS certificate, and then, if it meets the application's security requirements, proceed to authenticate.Chilkat PHP Downloads
<?php
use Chilkat2\Cert;
use Chilkat2\Ftp2;
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
$ftp = new Ftp2();
$ftp->Hostname = 'www.authtls-ftps-server.com';
$ftp->Username = 'FTP_LOGIN';
$ftp->Password = 'FTP_PASSWORD';
$ftp->AuthTls = true;
$ftp->Port = 21;
// Connect to the FTP server using explicit TLS (AUTH TLS).
try {
$ftp->ConnectOnly();
// Get the FTP server's certificate.
$serverCert = new Cert();
$ftp->GetServerCert($serverCert);
// Now that we have the certificate, we can check it in any way we desire.
// (See the online reference documentation for the certificate object's methods
// and properties)...
// Assuming the certificate is OK, proceed to authenticate with the FTP server.
$ftp->LoginAfterConnectOnly();
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Proceed with uploading/download files, etc...
//
$ftp->Disconnect();
echo "Success.\n";