How can one ensure secure FTP connections when transferring files in PHP?

To ensure secure FTP connections when transferring files in PHP, you should use FTPS (FTP over SSL/TLS) instead of regular FTP. This will encrypt the data being transferred, providing a secure connection. You can achieve this by setting the `ftp_ssl_connect` function to true when connecting to the FTP server.

// Connect to FTP server using FTPS
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';

$conn_id = ftp_ssl_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

if (!$conn_id || !$login_result) {
    die('FTP connection failed!');
}

// Transfer files securely
ftp_put($conn_id, 'remote_file.txt', 'local_file.txt', FTP_BINARY);

// Close the FTP connection
ftp_close($conn_id);