Skip to content

Commit

Permalink
Fixed issue with files/directories containing spaces. Added a functio…
Browse files Browse the repository at this point in the history
…n which determines the file's name with a regex.
  • Loading branch information
Daim Piekaerts committed Oct 23, 2017
1 parent db27561 commit 39cba3f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/FtpClient/FtpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
];

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 39cba3f

Please sign in to comment.