Skip to content

Commit

Permalink
Check for resource or FTP\Connection instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Nov 28, 2021
1 parent 3ca8f15 commit 87d045a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Adapter/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use League\Flysystem\Util;
use League\Flysystem\Util\MimeType;

use function in_array;

class Ftp extends AbstractFtpAdapter
{
use StreamedCopyTrait;
Expand Down Expand Up @@ -235,7 +237,7 @@ protected function login()
*/
public function disconnect()
{
if (is_resource($this->connection)) {
if ($this->hasFtpConnection()) {
@ftp_close($this->connection);
}

Expand Down Expand Up @@ -536,8 +538,7 @@ protected function listDirectoryContentsRecursive($directory)
*/
public function isConnected()
{
return is_resource($this->connection)
&& $this->getRawExecResponseCode('NOOP') === 200;
return $this->hasFtpConnection() && $this->getRawExecResponseCode('NOOP') === 200;
}

/**
Expand Down Expand Up @@ -575,4 +576,9 @@ private function getRawExecResponseCode($command)

return (int) preg_replace('/\D/', '', implode(' ', $response));
}

private function hasFtpConnection(): bool
{
return is_resource($this->connection) || $this->connection instanceof \FTP\Connection;
}
}

0 comments on commit 87d045a

Please sign in to comment.