I learned that using ftps (´ftp_ssl_connect()´) under PHP for Windows is tough. You are asked to enter a long journey of building your own binaries to include Open SSL... I found advice on phpseclib as a replacement (but getting openssl.cnf right to support peer validation sounds pretty hard to me, too...).
Then I hit this article and its pleasingly simple example including working peer validation (to avoid Man-in-the-middle-Attacks) drew my attention to streams:
$uri = 'https://www.bankofamerica.com/';
$ctx = stream_context_create(['ssl' => [
'verify_peer' => true, // important
'cafile' => '/hard/path/to/cacert.pem',
'CN_match' => 'www.bankofamerica.com'
]]);
$html = file_get_contents($uri, FALSE, $ctx); // we are good
However, is this useful for ftp connections? Can I also use peer-validated stream contexts to open ftps streams? The php manual hints, ssl context options also apply to sftp, but lacks further guidance.
So I am wildly guessing:
$ctx = stream_context_create(['ftps' => [
'verify_peer' => true,
'cafile' => 'd:/sandbox/mycerts.pem',
'CN_match' => 'ftp-12345678.mywebhoster.com'
]]);
Right? Wrong? User+Password as options now? And then what? User/Password now? Or later? I am clueless...
- How do I scan the remote ftp directory contents to start with?
- How to I upload or download a file from an ftp server?
Is any of that even possible? (A few lines of code would be very helpful....) Or are streams only good for singular file access?
Update: Curl might do what I want (including peer validation and directory lsiting) as shown in this SO answer. Will examine later this week...