diff options
author | Robin McCorkell <rmccorkell@owncloud.com> | 2015-08-12 22:20:08 +0100 |
---|---|---|
committer | Robin McCorkell <rmccorkell@owncloud.com> | 2015-08-28 12:58:47 +0100 |
commit | 1084e3adc7636787a139b68335112715b187b3bb (patch) | |
tree | 5f3d22280f28ad0328f8ed811bbab3c3c1152831 /apps/files_external/lib/sftp.php | |
parent | cb1ef827028126dd55c21fc3f3720723e5cc25a6 (diff) | |
download | nextcloud-server-1084e3adc7636787a139b68335112715b187b3bb.tar.gz nextcloud-server-1084e3adc7636787a139b68335112715b187b3bb.zip |
Migrate SFTP_Key external storage to new API
The SFTP backend now supports public key authentication alongside
password authentication.
Diffstat (limited to 'apps/files_external/lib/sftp.php')
-rw-r--r-- | apps/files_external/lib/sftp.php | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 7f921b5342f..921e7283c66 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -40,10 +40,11 @@ use phpseclib\Net\SFTP\Stream; class SFTP extends \OC\Files\Storage\Common { private $host; private $user; - private $password; private $root; private $port = 22; + private $auth; + /** * @var SFTP */ @@ -73,8 +74,15 @@ class SFTP extends \OC\Files\Storage\Common { } $this->user = $params['user']; - $this->password - = isset($params['password']) ? $params['password'] : ''; + + if (isset($params['public_key_auth'])) { + $this->auth = $params['public_key_auth']; + } elseif (isset($params['password'])) { + $this->auth = $params['password']; + } else { + throw new \UnexpectedValueException('no authentication parameters specified'); + } + $this->root = isset($params['root']) ? $this->cleanPath($params['root']) : '/'; @@ -112,7 +120,7 @@ class SFTP extends \OC\Files\Storage\Common { $this->writeHostKeys($hostKeys); } - if (!$this->client->login($this->user, $this->password)) { + if (!$this->client->login($this->user, $this->auth)) { throw new \Exception('Login failed'); } return $this->client; @@ -125,7 +133,6 @@ class SFTP extends \OC\Files\Storage\Common { if ( !isset($this->host) || !isset($this->user) - || !isset($this->password) ) { return false; } |