Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dasbrow's avatar

Error 110. Connection timed out SFTP

I have the following code that connects to a remote SFTP service. It seems the company likes to block IP's randomly for no reason. I need to deal with the the Connection time out, but can't seem to catch it.

use League\Flysystem\Sftp\SftpAdapter;

function xxxx() {

    $adapter = new SftpAdapter([
		'host' => $this->url,
		'port' => $this->port,
		'username' => $this->username,
		'password' => $this->password,
		'root' => $this->root,
		'timeout' => 10,
  ]);

try {

		$adapter->connect();
		
		// for redundancy
		if ($adapter->isConnected())
		{
			$filesystem = new Filesystem($adapter);

			return $filesystem;
		}
		else
		{
			return "ERROR, this shouldn't happen!";
		}
	
	} catch (Exception $e) {
	   echo $e->getMessage();
           Log::debug('Connection issue');
	}

}

I've tried catch (Exception $e), catch (League\Flysystem\ConnectionErrorException $e) and catch (League\Flysystem\Sftp\ConnectionErrorException $e)

Thanks.

0 likes
0 replies

Please or to participate in this conversation.