From 267cb5f3467d962b0ea86c15a45c7d855af8bcdd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 9 Nov 2020 13:29:59 +0100 Subject: [PATCH] FtpServer, SshServer: gracefully closes connection before reconnect fixes ftp_close(): SSL write failed --- src/Deployment/FtpServer.php | 3 +++ src/Deployment/RetryServer.php | 2 +- src/Deployment/SshServer.php | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Deployment/FtpServer.php b/src/Deployment/FtpServer.php index 2992b101..d5745bcd 100644 --- a/src/Deployment/FtpServer.php +++ b/src/Deployment/FtpServer.php @@ -64,6 +64,9 @@ public function __construct(string $url, bool $passiveMode = true) */ public function connect(): void { + if ($this->connection) { // reconnect? + @ftp_close($this->connection); // @ may fail + } $this->connection = $this->url['scheme'] === 'ftp' ? Safe::ftp_connect($this->url['host'], $this->url['port'] ?? 21) : Safe::ftp_ssl_connect($this->url['host'], $this->url['port'] ?? 21); diff --git a/src/Deployment/RetryServer.php b/src/Deployment/RetryServer.php index cde488cd..2e673875 100644 --- a/src/Deployment/RetryServer.php +++ b/src/Deployment/RetryServer.php @@ -115,7 +115,7 @@ private function retry(string $method, array $args) if ($counter < self::RETRIES) { if ($e->getMessage() !== $lastError) { $lastError = $e->getMessage(); - $this->logger->log("Error: $lastError", 'red'); + $this->logger->log("Error: $e", 'red'); } if ($method !== 'connect') { diff --git a/src/Deployment/SshServer.php b/src/Deployment/SshServer.php index cd37e43d..e7cac812 100644 --- a/src/Deployment/SshServer.php +++ b/src/Deployment/SshServer.php @@ -72,6 +72,9 @@ public function __construct( */ public function connect(): void { + if ($this->connection) { // reconnect? + @ssh2_disconnect($this->connection); // @ may fail + } $this->connection = Safe::ssh2_connect($this->url['host'], $this->url['port'] ?? 22); if (isset($this->url['pass'])) { Safe::ssh2_auth_password($this->connection, urldecode($this->url['user']), urldecode($this->url['pass']));