public function rawlist($directory = '.', $recursive = false)
{
if (!$this->isDir($directory)) {
throw new FtpException('"' . $directory . '" is not a directory.');
}
$list = $this->ftp->rawlist($directory);
$items = array();
if (!$list) {
return $items;
}
if (false == $recursive) {
foreach ($list as $path => $item) {
$chunks = preg_split("/\\s+/", $item);
// if not "name"
if (empty($chunks[8]) || $chunks[8] == '.' || $chunks[8] == '..') {
continue;
}
$path = $directory . '/' . $chunks[8];
if (isset($chunks[9])) {
$nbChunks = count($chunks);
for ($i = 9; $i < $nbChunks; $i++) {
$path .= ' ' . $chunks[$i];
}
}
if (substr($path, 0, 2) == './') {
$path = substr($path, 2);
}
$items[$this->rawToType($item) . '#' . $path] = $item;
}
return $items;
}
$path = '';
foreach ($list as $item) {
$len = strlen($item);
if (!$len || ($item[$len - 1] == '.' && $item[$len - 2] == ' ' or $item[$len - 1] == '.' && $item[$len - 2] == '.' && $item[$len - 3] == ' ')) {
continue;
}
$chunks = preg_split("/\\s+/", $item);
// if not "name"
if (empty($chunks[8]) || $chunks[8] == '.' || $chunks[8] == '..') {
continue;
}
$path = $directory . '/' . $chunks[8];
if (isset($chunks[9])) {
$nbChunks = count($chunks);
for ($i = 9; $i < $nbChunks; $i++) {
$path .= ' ' . $chunks[$i];
}
}
if (substr($path, 0, 2) == './') {
$path = substr($path, 2);
}
$items[$this->rawToType($item) . '#' . $path] = $item;
if ($item[0] == 'd') {
$sublist = $this->rawlist($path, true);
foreach ($sublist as $subpath => $subitem) {
$items[$subpath] = $subitem;
}
}
}
return $items;
}