I’ve made every possible connection to verify that the FTP server is working correctly, and can even use file_put_contents() to upload a file, but PHP’s FTP functions are not working for me when attempting an SSL connection. The server is configured to not allow connections that are not SSL, so there is no fallback. That’s OK, everything still works, but I really want to use ftp_ssl_connect() and ftp_login() to work!
See this example:
<?php
$username = 'someuser';
$password = 'SeCrEtPassWd';
$hostname = '192.168.1.10';
$filename = 'whatever.txt';
$string_data = 'This is the text content of the file. Pretty fancy eh?';
// USE file_put_contents W/ stream_context_create - WORKS !!!!
$url = 'ftps://' . $username . ':' . $password . '@' . $hostname . '/';
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create( $opts );
file_put_contents( $url . $filename, $string_data, 0, $context );
// END of code that works -----------------------------------
// USE PHP's FTP functions - DOES NOT WORK !!!
$conn_id = @ftp_ssl_connect( $hostname );
$login_result = ftp_login( $conn_id, $username, $password );
ftp_put( $conn_id, $filename, $filename, FTP_ASCII );
ftp_close( $conn_id );
// END of code that does not work ---------------------------
/*
ERRORS PERTAINING TO THE PROBLEM ----------------------------
Warning: ftp_login() [function.ftp-login]: SSL/TLS handshake failed in C:\\xampp\\htdocs\\script-library\\ftps.php on line 20
Warning: ftp_login() [function.ftp-login]: Proceed with negotiation. in C:\\xampp\\htdocs\\script-library\\ftps.php on line 20
*/
Is this a bug in PHP? I just don’t understand why everything else works, but not the PHP FTP functions. My problem is that I really need to be able to list the files on the remote server, because I don’t want to overwrite them. I would want to rename the file to something that doesn’t exist.