title: Connecting to FTPS using PHP and certificate as auth
body: <p>I'm having a hard time setting up a connection to a FTPS. </p>
  
  <p>I'm supposed to connect using SSL/TLS and AUTH (explicit standard).
  I've got a server address and a port (:60000) and a public key from the server owner as well as a certificate of my own. </p>
  
  <p>After googling around I think curl is my best option but I don't really know what curl options to use. </p>
  
  <p>Does anyone have a working example on a snippet which connects and uploads/downloads a file to such a FTPS?</p>
  
  <p>This page has some info <a href="http://php.net/manual/en/function.curl-setopt.php" rel="noreferrer">http://php.net/manual/en/function.curl-setopt.php</a>
  E.g dong the same think but using username/password </p>
  
  <pre><code>$username = 'username';
  $password = 'password';
  $url = 'example.com';
  $ftp_server = "ftp://" . $username . ":" . $password . "@" . $url;
  
  echo "Starting CURL.\n";
  $ch = curl_init();
  echo "Set CURL URL.\n";
  
  //curl FTP
  curl_setopt($ch, CURLOPT_URL, $ftp_server);
  
  //For Debugging
  //curl_setopt($ch, CURLOPT_VERBOSE, TRUE);   
  
  //SSL Settings
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
  
  //List FTP files and directories
  curl_setopt($ch, CURLOPT_FTPLISTONLY, TRUE);
  
  //Output to curl_exec
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  echo "Executing CURL.\n";
  $output = curl_exec($ch);
  curl_close($ch);
  echo "Closing CURL.\n";
  echo $output . "\n";
  $files = explode("\n", $output);
  print_r($files);
  </code></pre>
  
  <p>Any ideas how to use a certificate instead? </p>
  
  <p>Thanks in advance!</p>