title: FTPS with CURL PHP
body: <p>I'm busy with a curl php library which needs to connect to an FTPS server.</p>
  
  <p>I have this semi working... If I connect to <a href="ftp://domain.com" rel="nofollow noreferrer">ftp://domain.com</a> then it does work. If I watch the comms on the server with tcpflow I see it logging in with AUTH TLS and and all the comms is encrypted. The file is uploaded so all's good..</p>
  
  <p>What I'm unsure of is if its valid to try connecting instead to ftps://domain.com?</p>
  
  <p>The reason I'm asking is because if I change the protocol from ftp to ftps in curl then the login fails and the server (watching tcpflow comms) says that the login has failed:</p>
  
  <pre><code>191.101.002.204.00021-088.099.012.154.51630: 530 Please login with USER and PASS.
  </code></pre>
  
  <p>Also, when I watch the comms when trying to connect to ftps:// I don't see the client issuing the AUTH TLS command as it does with plain ftp://</p>
  
  <p>The problem I have is that it seems that my client's FTP server we have to ultimately connect to doesn't seem to allow connections without the ftps:// protocol.</p>
  
  <p>If I connect using lftp I can do so using ftps:// but then I have to disable ssl:
      set <a href="ftp://ssl-allow" rel="nofollow noreferrer">ftp://ssl-allow</a> no</p>
  
  <p>If I try the lftp connection using ftp:// it just hangs on the login command...</p>
  
  <p>I'm not really that experienced with FTP or TLS / SSL so I don't know if its maybe because the client's server doesn't have the certificates set up correctly..</p>
  
  <p>Here is a portion of my curl code which works with ftp:// but not ftps://</p>
  
  <pre><code> // Works
   $url = "ftp://proxy.plettretreat.co.za/";
   // Does not work
   $url = "ftps://proxy.plettretreat.co.za/";
   $port = 990;
   $username = "ftpuser";
   $password = "pass";   
  
   $filename = "/test.php";
   $file = dirname(__FILE__)."/test.php";
  
   $c = curl_init();
  
   // check for successful connection
   if ( ! $c)
        throw new Exception( 'Could not initialize cURL.' );
  
   $options = array(
        CURLOPT_USERPWD        =&gt; $username.':'.$password,
        CURLOPT_SSL_VERIFYPEER =&gt;     0,
        CURLOPT_SSL_VERIFYHOST =&gt;     0,
        CURLOPT_RETURNTRANSFER =&gt;     1,
        CURLOPT_BINARYTRANSFER =&gt;     1,          
        CURLOPT_FTP_SSL        =&gt; CURLFTPSSL_ALL, // require SSL For both control and data connections
        CURLOPT_FTPSSLAUTH     =&gt; CURLFTPAUTH_TLS, // let cURL choose the FTP authentication method (either SSL or TLS)
        CURLOPT_UPLOAD         =&gt; true,
        CURLOPT_PORT           =&gt; $port,
        CURLOPT_TIMEOUT        =&gt; 30,
   );
  </code></pre>
  
  <p>Another thing I'm unsure of is that my client has given me an IP address to connect to.. Can an IP address be used in ftps? I would have thought that certificates are mostly certifying a domain name?</p>
  
  <p>tl;dr</p>
  
  <p>1) Can I use ftps://domain.com to connect using CURL PHP?
  2) If I can use ftps:// in curl, then how do I get curl to log in (issue auth tls command)?
  3) Can an FTP server use SSL / TLS with only an IP address?</p>
  
  <p>Thanks...</p>
  
  <p>John</p>