title: Why does PHP ftp_connect fail when the server is running?
body: <p>I've been trying to connect via FTP to my server for some time now and can't seem to get it to work.</p>
  
  <pre><code>$connection_id = ftp_connect("example.com", 22);
  </code></pre>
  
  <p>When running this code, it hangs for sometime until PHP eventually tells me the script has been executing for too long and quits. It does not fail and return FALSE. It just times out.</p>
  
  <p>My first instinct was that maybe the server was down, so I pinged it. The ping was successful and I didn't lose any packets. Then I tried using the <strong>same parameters to connect with Filezilla and it was able to connect</strong>. I can also SSH to the server. I even tried extending the execution time PHP allows for the script but it always hangs up and times out.</p>
  
  <p>So what stumps me is that if all these methods of connecting to the server work, then why won't ftp_connect() function work? </p>
  
  <p><strong>CLARIFICATION:</strong></p>
  
  <p>Some of you have wondered why am I using port 22 (the SSH port) for connecting. I tried the default port for FTP (Port 21) at first, but the ftp_connect() function immediately returned FALSE, which according to the PHP manual means there was some error. </p>
  
  <p>I was also <em>unable</em> to connect through Port 21 with FileZilla. So I decided to use the SFTP Port instead, which is Port 22. Doing this connected successfully in FileZilla.</p>