Skip to content

Commit

Permalink
feat: handle more ftp errors and provide more detailed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oprudkyi committed Dec 11, 2024
1 parent 5530364 commit 291c70a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/CurlFtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function deleteFile(string $path): void
[$code] = explode(' ', end($response), 2);

if ((int) $code !== 250) {
throw UnableToDeleteFile::atLocation($path, 'the file still exists');
throw UnableToDeleteFile::atLocation($path, 'unable to delete file : '.$this->connection->lastError().' '.implode(' ', $response));
}
}

Expand Down Expand Up @@ -395,6 +395,11 @@ public function setVisibility(string $path, string $visibility): void
$connection = $this->connection();
$request = sprintf('SITE CHMOD %o %s', $mode, $location);
$response = $this->rawCommand($connection, $request);

if (empty($response) || strpos(end($response), ' ') === false) {
throw UnableToSetVisibility::atLocation($path, $this->connection->lastError().' '.implode(' ', $response));
}

[$code, $errorMessage] = explode(' ', end($response), 2);
if ((int) $code !== 200) {
$errorMessage = 'unable to chmod the file by running SITE CHMOD: '.$errorMessage;
Expand Down Expand Up @@ -454,7 +459,13 @@ public function lastModified(string $path): FileAttributes
$connection = $this->connection();

$response = $this->rawCommand($connection, 'MDTM '.$location);

if (empty($response) || strpos(end($response), ' ') === false) {
throw UnableToRetrieveMetadata::lastModified($path, $this->connection->lastError().' '.implode(' ', $response));
}

[$code, $time] = explode(' ', end($response), 2);

if ($code !== '213') {
throw UnableToRetrieveMetadata::lastModified($path, $time);
}
Expand All @@ -481,7 +492,13 @@ public function fileSize(string $path): FileAttributes
{
$location = $this->prefixer()->prefixPath($path);
$response = $this->rawCommand($this->connection(), 'SIZE '.$location);

if (empty($response) || strpos(end($response), ' ') === false) {
throw UnableToRetrieveMetadata::fileSize($path, $this->connection->lastError().' '.implode(' ', $response));
}

[$code, $fileSize] = explode(' ', end($response), 2);

if ($code != '213') {
throw UnableToRetrieveMetadata::fileSize($path, $fileSize);
}
Expand Down Expand Up @@ -773,7 +790,13 @@ private function ensureDirectoryExists(string $dirname, ?string $visibility): vo
if ($mode !== false) {
$request = sprintf('SITE CHMOD %o %s', $mode, $location);
$response = $this->rawCommand($connection, $request);

if (empty($response) || strpos(end($response), ' ') === false) {
throw UnableToCreateDirectory::atLocation($dirPath, 'unable to chmod the directory by running SITE CHMOD: '.$this->connection->lastError().' '.implode(' ', $response));
}

[$code, $errorMessage] = explode(' ', end($response), 2);

if ((int) $code !== 200) {
$errorMessage = 'unable to chmod the directory by running SITE CHMOD: '.$errorMessage;
throw UnableToCreateDirectory::atLocation($dirPath, $errorMessage);
Expand Down

0 comments on commit 291c70a

Please sign in to comment.