[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

FTP Recurse

I need a PHP script or a PHP class that will log into ftp.somesite.com, and retrive a directory listing of all the files in that folder and recurse the directories below it. The data (directory listings) can be placed in a CSV or into MySQL or whatever - as long as I can parse and work with it.
0
DrDamnit
Asked:
DrDamnit
1 Solution
 
matt_mcswainCommented:
I had to remove the max execution time to view all the files on my server; it took a couple minutes. This will print them out tabbed appropriately using lists. You should be able to do whatever you want with the data by modifying the function.
And you need ftp enabled.

<?php
set_time_limit ( 0 );
$ftpServer = 'ftp.yourwebsite.com';
$user = 'username';
$pass = 'password';
$conn = ftp_connect($ftpServer);
$login = ftp_login($conn, $user, $pass);

if ((!$conn) || (!$login))
     die('FTP connection failed!');
dir_tree('.',$conn);//current directory
ftp_close($conn);

function dir_tree($dir,$conn) {
  echo '<ul>';
  $detail = ftp_rawlist($conn, $dir);
  $list   = ftp_nlist($conn, $dir);
  for($i=0;$i<count($list);$i++) {
     echo '<li>'.$list[$i].'</li>';
     if ($detail[$i]{0} == 'd') dir_tree($list[$i],$conn);
   }
   echo '</ul>';
}
?>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now