From 87d045a5c7bd65e3ffb591675d2fabf016651ce6 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sun, 28 Nov 2021 20:40:12 +0100 Subject: [PATCH] Check for resource or FTP\Connection instance. --- src/Adapter/Ftp.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Adapter/Ftp.php b/src/Adapter/Ftp.php index 22065b842..caa8b91d8 100644 --- a/src/Adapter/Ftp.php +++ b/src/Adapter/Ftp.php @@ -11,6 +11,8 @@ use League\Flysystem\Util; use League\Flysystem\Util\MimeType; +use function in_array; + class Ftp extends AbstractFtpAdapter { use StreamedCopyTrait; @@ -235,7 +237,7 @@ protected function login() */ public function disconnect() { - if (is_resource($this->connection)) { + if ($this->hasFtpConnection()) { @ftp_close($this->connection); } @@ -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; } /** @@ -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; + } }