// opendir wrapper data channel encryption fails with IIS FTP 7.5, 8.5

 [2016-08-05 13:05 UTC] vhu at iki dot fi

Description:
------------
Fix for bug #72667 changed the FTP/FTPS wrapper php_stream_ftp_opendir() so that the data channel is opened immediately after the PASV/EPSV command. If FTPS is enabled, data channel encryption is negotiated immediately after opening the data channel.

IIS FTP server and ProFTPD only allow TLS negotiation after NLST command has been issued and data ready to be transmitted. As it is, FTPS opendir() and scandir() against IIS or ProFTPD effectively hang until the negotiation times out.


Test script:
---------------
<?php
foreach (scandir('ftps://example.com/') as $fn) {
  print $fn ."\n";
}


Expected result:
----------------
file1
file2
file3

Actual result:
--------------
Warning: scandir(): SSL: Handshake timed out in test.php on line 2

Warning: scandir(ftps://example.com/): failed to open dir: Unable to activate SSL mode in test.php on line 2

Warning: scandir(): (errno 0): Success in test.php on line 2

Warning: Invalid argument supplied for foreach() in test.php on line 2