Search code examples
phpsslftpftps

ftp_nlist(): data_accept: SSL/TLS handshake failed


Once upon a time, there was a normalish error in PHP land:

Warning: ftp_nlist(): data_accept: SSL/TLS handshake failed in [path] on line 29

But here's the catch, "line 29" is not the connection or login, note how it referenced the ftp_nlist() function:

$ftp = ftp_ssl_connect($cred['host'], $cred['port'], 180);
if (!ftp_login($ftp, $cred['user'], $cred['pass'])) {die("Login Failed");}
ftp_pasv($ftp, true);

$files = ftp_nlist($ftp, '');

OpenSSL is compiled and enabled in phpinfo() as suggested here: ftp_login() : SSL/TLS handshake failed

Other posts I've seen all seem to reference error in the ftp_ssl_connect() or ftp_login() commands which work for me. What can I check when ftp_login() returns true?

Or... are there any logs to get more details on what is wrong?

I'm using php 5.3.29. The code does work properly on my desktop (php 7), but I'm hoping I don't have to upgrade the server to 7 for this to work

12-28-2017 update: Upgrading to 5.6 resolved, so looks like Martin is on point.


Solution

  • The ftp_nlist opens a data connection. That connection needs TLS/SSL handshake too.

    As the control connection handshake succeeded, the problem indeed cannot be with an absent TLS/SSL support in PHP. Neither the problem can be with anything like the server and PHP not being able to find a cipher to agree on.

    When TLS/SSL handshake on data connection fails after handshake on control connection succeeded, it's quite usually because the client (PHP) did not reuse TLS/SSL session from control connection on the data connection (see Why is session reuse useful in FTPS?). Some servers do require that. PHP supports the reuse only since 5.6.26. See PHP Bug 70195. So make sure you use that version of PHP at least.