Skip to content

Commit

Permalink
FtpServer, SshServer: gracefully closes connection before reconnect
Browse files Browse the repository at this point in the history
fixes ftp_close(): SSL write failed
  • Loading branch information
dg committed Nov 9, 2020
1 parent c05a246 commit 267cb5f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Deployment/FtpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Deployment/RetryServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 3 additions & 0 deletions src/Deployment/SshServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down

0 comments on commit 267cb5f

Please sign in to comment.