Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,32 @@ protected function login()

$authentication = $this->getAuthentication();

$this->attemptLogin($authentication);

if ($authentication instanceof Agent) {
$authentication->startSSHForwarding($this->connection);
}
}

/**
* Attempt Login
*
* @param Agent|RSA|string $authentication
*
* @throws ConnectionErrorException
*/
private function attemptLogin($authentication)
{
if ($this->connection->login($this->getUsername(), $authentication)) {
goto past_login;
return;
}

// try double authentication, key is already given so now give password
if ($authentication instanceof RSA && $this->connection->login($this->getUsername(), $this->getPassword())) {
goto past_login;
return;
}

throw new ConnectionErrorException('Could not login with username: '.$this->getUsername().', host: '.$this->host);

past_login:

if ($authentication instanceof Agent) {
$authentication->startSSHForwarding($this->connection);
}
}

/**
Expand Down