Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

PHP: ftp_login fails with "failed to create the SSL context"

0

51 views

I'm trying to upload a file to a remote FTP server (which requires FTPES) using PHP. The script I've written works locally, but on the live server ftp_login() returns false and the following warnings appear in the error log:

PHP Warning:  ftp_login(): failed to create the SSL context [...]
PHP Warning:  ftp_login(): AUTH command ok; starting SSL connection. [...]

I know that the login details are correct (since identical code works locally). I can successfully connect to the FTP server from the live server using curl on the command line.

The server is running PHP 5.3.3 (Zend Server on CentOS). I can see from phpinfo that the PHP configure command includes -with-openssl=/usr/local/openssl-0.9.8o

The code is simply this:

$ftpConnection = ftp_ssl_connect('hostname');
if (!$ftpConnection) {
    echo "Failed to connect to FTP Site\n";
    return false;
}
if (!ftp_login($ftpConnection, 'xxxxx', 'xxxxx')) {
    echo "Failed to login to FTP site\n";
    return false;
}

For reference my local box (where this works fine) is running PHP 5.3.3-1ubuntu9.3.

Can anyone point me in the right direction?

asked March 11, 2011 10:47 am CST
posted via StackOverflow

1 Answers

0
 

I eventually solved this problem by changing the code to use the PHP cURL functions instead, since I knew I could connect okay from the command line with that. There probably is way to get this working with the FTP functions, but in case this helps anyone else here's my working cURL version:

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => 'ftp://username:password@hostname/path/to/file'
    CURLOPT_UPLOAD => 1,
    CURLOPT_INFILE => $fp,
    CURLOPT_INFILESIZE => $localFileSize,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_FTP_SSL => CURLFTPSSL_TRY,
    CURLOPT_VERBOSE => true
));

if (curl_exec($ch)) {
    curl_close($ch);
}

answered March 12, 2011 12:20 am CST

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Tomcat context paths
January 6, 2011