public function copy(string $pathFrom, string $pathTo)
{
$pathTo = $this->getFilePath($pathTo);
// Try creating the directory first
if ($this->createDirectoriesAutomatically) {
try {
$this->mkdir(dirname($pathTo));
} catch (DirectoryNotCreatedException $e) {
throw new FileNotCopiedException(sprintf('File %s cannot be copied to %s.', $pathFrom, $pathTo), 0, $e);
}
}
$requests = [];
foreach ($this->servers as $server) {
$requests[$server] = $this->createRequest($server, $this->getFilePath($pathFrom), self::METHOD_COPY, ['Destination' => $server . $pathTo]);
}
foreach ($this->sendAllRequests($requests) as $response) {
// 201 means copied
if (self::STATUS_201_CREATED !== $response->getStatusCode()) {
throw new FileNotCopiedException(sprintf('File %s cannot be copied to %s.', $pathFrom, $pathTo));
}
}
}