In PHP, ftp_ssl_connect() opens a secure FTP connection over SSL/TLS. It is the secure version of ftp_connect().
The connection is encrypted, so your username, password and files are protected while they travel over the network. This function is only available when PHP was built with OpenSSL support.
Syntax
Call ftp_ssl_connect() with the values you need. Start with this line.
Opens a secure connection on the default port 21 with a 90 second timeout.
ftp_ssl_connect('ftp.example.com', 21, 30)
Uses a 30 second timeout for network operations.
function_exists('ftp_ssl_connect')
Checks that your PHP has OpenSSL support before you call the function.
ftp_ssl_connect() needs OpenSSL. If the function does not exist, your PHP build was made without it, and you should enable OpenSSL in php.ini or your hosting panel. You still log in with ftp_login() after connecting. This is explicit FTPS, not SFTP, which is a different protocol.
Library declarations
PHP
ftp_ssl_connect(string $hostname, int $port = 21, int $timeout = 90): FTP\Connection|false
Parameters
Parameter
Description
hostname
Required. The FTP server address, such as ftp.example.com. Do not add ftp:// at the start.
port
Optional. The port of the FTP server. The default is 21.
timeout
Optional. The timeout in seconds for network operations. The default is 90.
Return Value
Return Value
Description
FTP\Connection|false
Returns an FTP\Connection object on success or false on failure.
PHP Examples
Example 1 — Open a Secure Connection
Connect to a server over SSL/TLS and log in.
PHP
<?php
$ftp = ftp_ssl_connect('ftp.example.com');
if ($ftp === false) {
die("Could not connect securely");
}
if (ftp_login($ftp, 'demo', 'secret')) {
echo "Secure login successful", PHP_EOL;
}
ftp_close($ftp);
Output
Secure login successful
How It Works
ftp_ssl_connect() opens an encrypted connection to the server.
If it returns false, the script stops with a clear message.
ftp_login() then sends the username and password over the encrypted channel.
ftp_close() ends the session when we are done.
Example 2 — Check That OpenSSL Is Available
Before using ftp_ssl_connect(), confirm the function exists so you can fall back or show a helpful message.
PHP
<?php
if (!function_exists('ftp_ssl_connect')) {
echo "OpenSSL support is missing in this PHP build", PHP_EOL;
exit;
}
$ftp = ftp_ssl_connect('ftp.example.com', 21, 30);
echo $ftp ? "Connected securely" : "Connection failed", PHP_EOL;
if ($ftp) {
ftp_close($ftp);
}
Output
Connected securely
How It Works
function_exists() tells you if PHP was built with OpenSSL support.
If the function is missing, the script prints a message and stops.
Otherwise ftp_ssl_connect() tries to connect with a 30 second timeout.
The result is checked before ftp_close() so we never close a false value.
Example 3 — Secure Upload with a Longer Timeout
Open a secure connection, raise the timeout, and upload a file in passive mode.