title: Can't connect to FTP with PHP ftp_connect from localhost
body: <p>I I've been trying to make some script to download files through FTP from my localhost Apache in CentOS and I can't get it to work!</p>
  
  <p>The code I am using is the very one used by any basic ftp request:</p>
  
  <pre><code>&lt;?php
  $ip= FTP_IP_HERE;
  $port='21';
  $timeout='90';
  $un='username';
  $pw='password';
  
  // Connect to ftp
  $conn_id = ftp_connect($ip,$port,$timeout);
  
  // Open a session to an external ftp site
  $login_result = ftp_login ($conn_id, $un, $pw);
  
  // Check open
  if ((!$conn_id) || (!$login_result)) {
      print "FTP connection failed!";
      exit();
  }
  
  // turn on passive mode transfers
  if (ftp_pasv($conn_id, true) == FALSE) {
      print "Passive FTP connection failed!";
      exit();
  }
  </code></pre>
  
  <p>I tried the same script on remote server and it worked!
  I am not sure if it is any apache configuration to be done, or a PHP limitation itself.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Here is the error log:</p>
  
  <pre><code>Warning: ftp_login() expects parameter 1 to be resource, boolean given in /var/www/html/ftp/FTP.php on line 16
  
  Warning: ftp_get() expects parameter 1 to be resource, boolean given in /var/www/html/ftp/FTP.php on line 22
  Falha ao enviar o arquivo test.pdf&lt;br /&gt;Array
  (
      [type] =&gt; 2
      [message] =&gt; ftp_get() expects parameter 1 to be resource, boolean given
      [file] =&gt; /var/www/html/ftp/FTP.php
      [line] =&gt; 22
  )
  
  Warning: ftp_close() expects parameter 1 to be resource, boolean given in /var/www/html/ftp/FTP.php on line 30
  </code></pre>