From: clancy_1 on
I had a procedure for listing the files on a remote directory recursively using FTP, using
the code below. I thought it was working, but when I tried to use it yesterday I found it
listed every second directory, and returned false for the others.

I then tried replacing line A with line B (shown at the end of the procedure). The
procedure then worked (usually), but the number of times I had to try the ftp_rawlist was
most often 2, but varied randomly from 1 to 5, and on one occasion failed after five
tries.

I get the feeling that for some reason the system takes some time to recover after one
invocation of ftp_rawlist, before it is ready to run it again, but I can find no
indication of why this should be so, or what I can do about it.

Can anyone cast any light on this? My remote website is running under PHP 5.1.6

(I have now investigated the recursive option on this command, and realise that I should
use this, instead of calling the procedure recursively, although this will require a
significant amount of work to implement.)

Clancy

/* ---------------------------------------------------------------
1.0 List the contents of remote directory $source recursively
---------------------------------------------------------------*/
function list_recsv ($conn_id, $source_dir, $recsv)
{
//echo '<h5>Rndx_'.__LINE__.': Source_dir = '.$source_dir.'</h5>';
set_time_limit(5);
$files = ftp_rawlist ($ftp_id, $source_dir) // Line A
$i = 0; $j = 0; $n = count ($files); $sub_dirs = '';
echo '<h5>&nbsp;</h5><h5>TB_11_'.__LINE__.': Get_recsv: '.$source_dir.' has '.$n.' files,
Try = '.$try.'</h5>';
while ($i < $n)
{
$aa = decrypt ($files[$i]);
// (Code to list files removed)

if (substr($aa[0], 0, 1) == 'd')
{
$sub_dirs[$j++] = $aa[8];
}
++$i;
}
if ($recsv)
{$i = 0; while ($i < $j)
{
$file = $sub_dirs[$i++];
$new_source = $source_dir.$file;
list_recsv ($ftp_id, $new_source, $recsv, $down_load);
}
}
}

Line B: $try = 1;
while ((($files = ftp_rawlist ($ftp_id, $source_dir)) == false) && $try < 5) { ++$try; }