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:
$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.
Is openssl compiled into this php build?
Secondly, are you certain you're supposed to be connecting with ftps and not sftp?
Well, OpenSSL is showing as enabled when I look at phpinfo(). I can access the website using http://...
So I don't know if that means openssl is compiled in this php build or not. The dev machine is running XAMPP on Windows 7 64 bit, if that means anything.
And yes, I must connect with ftps and not sftp.
I actually came up with a solution using is_file and the ftps:// wrapper. I won't actually need to get the FTP functions working anymore, but it would be better if I did, because it means doing extra work on my end.
This topic is now closed. New replies are no longer allowed.