title: PHP - Get all files from all directories in FTP
body: <p>i have this doubt, i can download all files from an specific directory, but how can i download all files from all directories in an specific folder?
  My code to download from a directory is like this:</p>
  
  <pre><code>$ftp_server = "server";
  $ftp_user = "user";
  $ftp_pass = "pass";
  
  $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
  
  function get_file($strDir) {
      global $conn_id;
      $contents = ftp_nlist($conn_id, $strDir);   
      for($i=0; $i&lt;count($contents); $i++) {
          if (strstr($contents[$i], "OUT") !== FALSE) {
              if (ftp_get($conn_id, substr($contents[$i],1), $contents[$i], FTP_ASCII)) {
                  echo "Successfully written to ".substr($contents[$i],1)."&lt;br&gt;";
              } else {
                  echo "There was a problem ".substr($contents[$i],1)."&lt;br&gt;";
              }
  
          }
          else {
              mkdir(substr($contents[$i],1),0777,true);                   
              $a = get_file($contents[$i]);
          }
      }
      return 1;
  }
  
  if (ftp_login($conn_id, $ftp_user, $ftp_pass)) {
      $contents = ftp_nlist($conn_id, "OUT");
      for($i=0; $i&lt;count($contents); $i++) {
              echo "Directory = " . $contents[$i] . "&lt;br&gt;";   
              ftp_get($conn_id, $contents[$i], $contents[$i], FTP_BINARY);
      }
  }
  </code></pre>
  
  <p>so, how can i download ALL the files from ALL directories?</p>