title: Getting FTP error for timeout with PHP & Codeigniter
body: <p>I'm trying to send files via FTP using PHP and Codeigniter. I'm actually not using the Codeigniter FTP class as it doesn't do what I need, so for this it's native PHP.</p>
  
  <p>Basically what I need is for the script to do an action if the file sent times out. Currently my code is this:</p>
  
  <pre><code>// connect to the ftp server
  $connection = ftp_connect($item_server);
  
  // login to the ftp account
  $login = ftp_login($connection, $item_username, $item_password);
  
  // if the connection or account login failed, change status to failed
  if (!$connection || !$login) 
      { 
          // do the connection failed action here
      }
  else
      {
  
  // set the destination for the file to be uploaded to
  $destination = "./".$item_directory.$item_filename;
  
  // set the source file to be sent
  $source = "./assets/photos/highres/".$item_filename;
  
  // upload the file to the ftp server
  $upload = ftp_put($connection, $destination, $source, FTP_BINARY);
  
  // if the upload failed, change the status to failed
  if (!$upload) 
      {
          // do the file upload failed action here
      }
  // fi the upload succeeded, change the status to sent and close the ftp connection
  else 
  {
      ftp_close($connection);
      // update the item's status as 'sent'
  // do the completed action here
      }
  
  }
  </code></pre>
  
  <p>So basically the script connects to a server and attempts to drop the file in. It currently does an action if the connection could not be established, or if the file could not be dropped in. But I think for timeout it just sits there giving no response. I need a response for everything as it's running in an automated script and the only way for the user to know what's going on is if the script tells them. </p>
  
  <p>How can I get a response if the server times out?</p>
  
  <p>Any help is most appreciated :)</p>