diff --git a/src/PhpseclibV3/SimpleConnectivityChecker.php b/src/PhpseclibV3/SimpleConnectivityChecker.php index 3554c0d42..6773bf67d 100644 --- a/src/PhpseclibV3/SimpleConnectivityChecker.php +++ b/src/PhpseclibV3/SimpleConnectivityChecker.php @@ -9,12 +9,34 @@ class SimpleConnectivityChecker implements ConnectivityChecker { + public function __construct( + private bool $usePing = false, + ) { + } + + public static function create(): SimpleConnectivityChecker + { + return new SimpleConnectivityChecker(); + } + + public function withUsingPing(bool $usePing): SimpleConnectivityChecker + { + $clone = clone $this; + $clone->usePing = $usePing; + + return $clone; + } + public function isConnected(SFTP $connection): bool { if ( ! $connection->isConnected()) { return false; } + if ( ! $this->usePing) { + return true; + } + try { return $connection->ping(); } catch (Throwable) {