I'm writing a script that reads a whole ftp server and puts all the filenames and directory names into an array. The problem is that somehow all the files more than one directory level deep do not get stored into the array, however the directories are properly stored.
Take this ftp server for example --> [url]ftp://ftp.c-logic.be/[/url]
The files in dirs "Formulieren/" and "Pers/" (sorry for the dutch) will be stored, files in "Dos/Collect/" won't.
What do I do wrong here ?
<?php
$ftp_server = "ftp.c-logic.be";
$ftp_user_name = "anonymous";
$ftp_user_pass = "anonymous";
$ftp_port = 21;
// make connection
$conn_id = @ftp_connect($ftp_server,$ftp_port);
// login with username and password
$login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if (!$conn_id) {
echo "FTP connectie is mislukt!<br>";
echo "Probeerde naar $ftp_server te verbinden met de gebruiker $ftp_user_name";
exit;
}
else if (!$login_result) {
echo "Inloggen is mislukt!<br>";
echo "Probeerde in te loggen met de gebruiker $ftp_user_name";
exit;
}
else echo "Verbonden met $ftp_server, als gebruiker $ftp_user_name";
// functions
function browseFTP($conn_id, $dir) {
static $flist = array();
if ($files = ftp_nlist($conn_id, $dir)) {
foreach ($files as $file) {
if (ftp_size($conn_id, $file) == "-1") {
$flist[] = $file;
browseFTP($conn_id, $file);
} else $flist[] = $file;
}
}
return $flist;
}
// get data
$filelist = browseFTP($conn_id, $dir='.');
print_r($filelist);
// close FTP stream
ftp_close($conn_id);
?>