note 57734 deleted from function.ftp-rawlist by nlopess
| From: | nlopess@php.net | Date: | Wed, 12 Oct 2005 19:46:08 +0000 |
| Subject: | note 57734 deleted from function.ftp-rawlist by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96913@lists.php.net to get a copy of this message | ||
Note Submitter: rob at SPAMMENOTrem5 dot com
----
When using this function within a recursive function, be sure to slow the script down a bit with:
sleep(1)
Otherwise in many cases php will crash because it cannot get the responses fast enough. (This is not
confirmed, but this fixed my problem)
<?php
function checkFTP(&$conn_id, $directory='.')
{
$dir = ftp_rawlist($conn_id, $directory);
sleep(1);
$tmp = array();
foreach($dir as $k => $v)
{
$split = preg_split("[ ]", $v, 9, PREG_SPLIT_NO_EMPTY);
if ($split[0] != "total")
{
$parsed[$k]['isdir'] = $split[0]{0} === "d";
$parsed[$k]['perms'] = $split[0];
$parsed[$k]['number'] = $split[1];
$parsed[$k]['owner'] = $split[2];
$parsed[$k]['group'] = $split[3];
$parsed[$k]['size'] = $split[4];
$parsed[$k]['month'] = $split[5];
$parsed[$k]['day'] = $split[6];
$parsed[$k]['time/year']= $split[7];
$parsed[$k]['name'] = $split[8];
}
}
foreach($parsed as $file)
{
if($file['isdir'] == 1)
{
$tmp2 = checkFTP($conn_id, $directory . "/" . $file['name']);
if(is_array($tmp2))
{
$tmp = array_merge($tmp, $tmp2);
}
}
else
{
array_push($tmp, str_replace(localmirror, '',
$directory."/".$file['name']));
}
}
return $tmp;
}
?>