Skip to content

Commit 8ed3417

Browse files
authored
Scandir not working if file contains spaces
1 parent dc45742 commit 8ed3417

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

FtpClient.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,23 @@ public function parseRawList(array $rawlist)
650650
}
651651
continue;
652652
}
653+
654+
// $chunks[8] and up contains filename (multiple elements if filename contains spaces)
655+
// up to last element or element containing '->' (if type is 'link')
656+
$target = '';
657+
$filename = '';
658+
$linkArrowElement = array_search('->', $chunks);
659+
if ($linkArrowElement !== false) {
660+
$filenameChunks = array_slice($chunks, 8, count($chunks) - $linkArrowElement -1);
661+
$filename = implode(' ', $filenameChunks);
662+
$targetChunks = array_slice($chunks, $linkArrowElement +1);
663+
$target = implode(' ', $targetChunks);
664+
} else {
665+
$filenameChunks = array_slice($chunks, 8);
666+
$filename = implode(' ', $filenameChunks);
667+
}
668+
669+
653670
$item = [
654671
'permissions' => $chunks[0],
655672
'number' => $chunks[1],
@@ -659,11 +676,11 @@ public function parseRawList(array $rawlist)
659676
'month' => $chunks[5],
660677
'day' => $chunks[6],
661678
'time' => $chunks[7],
662-
'name' => $chunks[8],
679+
'name' => $filename,
663680
'type' => $this->rawToType($chunks[0]),
664681
];
665682
if ($item['type'] == 'link') {
666-
$item['target'] = $chunks[10]; // 9 is "->"
683+
$item['target'] = $target;
667684
}
668685
// if the key is not the path, behavior of ftp_rawlist() PHP function
669686
if (is_int($key) || false === strpos($key, $item['name'])) {

0 commit comments

Comments
 (0)