/** * {@inheritdoc} */ public function connect() { $this->sftp = new SFTP($this->configuration->getHost(), $this->configuration->getPort()); switch ($this->configuration->getAuthenticationMethod()) { case ServerConfiguration::AUTH_BY_IDENTITY_FILE: $key = new RSA(); $key->loadKey(file_get_contents($this->configuration->getPrivateKey())); $result = $this->sftp->login($this->configuration->getUser(), $key); break; case ServerConfiguration::AUTH_BY_PEM_FILE: $key = new RSA(); $key->loadKey(file_get_contents($this->configuration->getPemFile())); $result = $this->sftp->login($this->configuration->getUser(), $key); break; case ServerConfiguration::AUTH_BY_AGENT: $key = new Agent(); $result = $this->sftp->login($this->configuration->getUser(), $key); break; default: throw new \RuntimeException('You need to specify authentication method.'); } if (!$result) { throw new \RuntimeException('Unable to login with the provided credentials.'); } }
private function initServer($config) { $serverConfiguration = new ServerConfiguration($config['ssh_host'], $config['ssh_user'], $config['ssh_port']); $serverConfiguration->setAuthenticationMethod(ServerConfiguration::AUTH_BY_IDENTITY_FILE)->setPrivateKey('~/.ssh/id_rsa')->setPublicKey('~/.ssh/id_rsa.pub'); $this->server->setConfiguration($serverConfiguration); }