From 39cba3f1a76ee0d3028cce778924978da593d3a9 Mon Sep 17 00:00:00 2001 From: Daim Piekaerts Date: Mon, 23 Oct 2017 10:15:08 +0200 Subject: [PATCH] Fixed issue with files/directories containing spaces. Added a function which determines the file's name with a regex. --- src/FtpClient/FtpClient.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/FtpClient/FtpClient.php b/src/FtpClient/FtpClient.php index cc31e17..849ee9f 100644 --- a/src/FtpClient/FtpClient.php +++ b/src/FtpClient/FtpClient.php @@ -792,7 +792,7 @@ public function parseRawList(array $rawlist) 'month' => $chunks[5], 'day' => $chunks[6], 'time' => $chunks[7], - 'name' => $chunks[8], + 'name' => $this->getItemNameFromRawList($child, $chunks), 'type' => $this->rawToType($chunks[0]), ]; @@ -874,4 +874,28 @@ protected function setWrapper(FtpWrapper $wrapper) return $this; } + + /** + * @param string $itemLine + * @param array $chunks + * + * @return string|null + */ + private function getItemNameFromRawList($itemLine, $chunks) + { + if (preg_match("/\d{2}:\d{2}/",$chunks[7])) { + $date = implode(' ', array_slice($chunks, 5, 3)); + } else { // Used when only year is given + $date = implode(' ', array_slice($chunks, 5, 2)) . " " . $chunks[7]; + } + + $regex = "/(?<=" . $date . "\s)[\.a-zA-Zа-яА-Я0-9_!\s]+/"; + preg_match($regex, $itemLine, $matches); + + if (!empty($matches)) { + return rtrim(array_shift($matches)); + } + + return null; + } }