mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
AcmeClient: Fixed not detecting remote side closing connection.
This commit is contained in:
+2
-2
@@ -62,7 +62,7 @@ class SftpClient
|
||||
|
||||
public function connected(): ?array
|
||||
{
|
||||
return $this->process
|
||||
return $this->process && $this->process->isRunning()
|
||||
? $this->connection_info
|
||||
: null;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class SftpClient
|
||||
// Creating the sftp process
|
||||
if ($this->process = Process::open($cmd)) {
|
||||
$this->processAvailableInput(self::CONNECT_REPLY_TIMEOUT, 1, null, 0.75);
|
||||
if ($error = $this->lastError()) {
|
||||
if (($error = $this->lastError()) || !$this->process->isRunning()) {
|
||||
Utils::log()->error("Failed connecting to '$host' (user: '$username')", $error);
|
||||
return false;
|
||||
}
|
||||
|
||||
+7
-3
@@ -140,9 +140,6 @@ class SftpUploader
|
||||
*/
|
||||
public function upload(): int
|
||||
{
|
||||
$connection = Utils::requireThat($this->sftp->connected(), "The sftp client must be connected");
|
||||
$username = $connection["user"];
|
||||
|
||||
// Correct state when we are restarted after an error
|
||||
if ($this->current_file) {
|
||||
// Restore the remote path to where we originally have been.
|
||||
@@ -182,6 +179,12 @@ class SftpUploader
|
||||
$this->sftp->clearError();
|
||||
|
||||
try {
|
||||
$connection = $this->sftp->connected();
|
||||
if (!$connection) {
|
||||
Utils::log()->error("The sftp client is not connected, upload stopped.");
|
||||
return self::UPLOAD_ERROR;
|
||||
}
|
||||
|
||||
// Changing remote directory if required.
|
||||
if (($target_dir = dirname($file["target"])) !== $remote_path) {
|
||||
|
||||
@@ -229,6 +232,7 @@ class SftpUploader
|
||||
}
|
||||
|
||||
// Preparing upload
|
||||
$username = $connection["user"];
|
||||
$remote_filename = basename((empty($file["target"]) ? $local_file : $file["target"]));
|
||||
$remote_file = $remote_files[$remote_filename] ?: ["type" => "-", "owner" => $username];
|
||||
$remote_is_file = $remote_file["type"] === "-";
|
||||
|
||||
@@ -179,7 +179,7 @@ function commandTestConnection(array &$options): int
|
||||
$result["actions"][] = "connected";
|
||||
$result["remote"] = array_merge($sftp->connected(), ["path" => $sftp->pwd()]);
|
||||
} else {
|
||||
$result = array_merge($result, $error);
|
||||
$result = array_merge($result, ($error ?: []));
|
||||
}
|
||||
|
||||
// Testing file upload
|
||||
|
||||
Reference in New Issue
Block a user