title: Is it possible to work with FTPS under PHP using stream context?
body: <p>I learned that using <strong>ftps</strong> (´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 <a href="http://phpseclib.sourceforge.net/" rel="nofollow noreferrer">phpseclib</a> as a replacement (but getting openssl.cnf right to support peer validation sounds pretty hard to me, too...).</p>
  
  <p>Then I hit <a href="https://wiki.php.net/rfc/tls-peer-verification#tls_peer_verification" rel="nofollow noreferrer">this article</a> and its pleasingly simple example including working peer validation (to avoid Man-in-the-middle-Attacks) drew my attention to streams:</p>
  
  <pre><code>$uri = 'https://www.bankofamerica.com/';
  $ctx = stream_context_create(['ssl' =&gt; [
      'verify_peer' =&gt; true, // important
      'cafile' =&gt; '/hard/path/to/cacert.pem',
      'CN_match' =&gt; 'www.bankofamerica.com'
  ]]);
  $html = file_get_contents($uri, FALSE, $ctx); // we are good
  </code></pre>
  
  <p>However, is this useful for ftp connections? <strong>Can I also use peer-validated stream contexts to open ftps streams?</strong> <a href="http://php.net/manual/en/context.ftp.php" rel="nofollow noreferrer">The php manual hints</a>, ssl context options also apply to sftp, but lacks further guidance.</p>
  
  <p><em>So I am wildly guessing:</em></p>
  
  <pre><code>$ctx = stream_context_create(['ftps' =&gt; [
      'verify_peer' =&gt; true,
      'cafile' =&gt; 'd:/sandbox/mycerts.pem',
      'CN_match' =&gt; 'ftp-12345678.mywebhoster.com'
  ]]);
  </code></pre>
  
  <p>Right? Wrong? User+Password as options now? And then what? User/Password now? Or later? I am clueless...</p>
  
  <ul>
  <li>How do I scan the remote ftp directory contents to start with? </li>
  <li>How to I upload or download a file from an ftp server? </li>
  </ul>
  
  <p>Is any of that even possible? (A few lines of code would be very helpful....) Or are streams only good for singular file access?</p>
  
  <p><em>Update</em>:
  Curl might do what I want (including peer validation and directory lsiting) <a href="https://stackoverflow.com/a/3698567/444255">as shown in this SO answer</a>. Will examine later this week...</p>