diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-25 02:52:25 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-25 02:52:25 -0800 |
commit | f6044fe42930b1268b185ab61e20c6d0aa424526 (patch) | |
tree | 052e88e6a6af76893a085c83b6582ac9f270b5bc /apps/files_external/lib/sftp.php | |
parent | bcf3704645c074be0fa2579eebdc363a2e379765 (diff) | |
parent | 6dd5bc0379505520867d3dbcba40d6dd95546f6a (diff) | |
download | nextcloud-server-f6044fe42930b1268b185ab61e20c6d0aa424526.tar.gz nextcloud-server-f6044fe42930b1268b185ab61e20c6d0aa424526.zip |
Merge pull request #14460 from owncloud/revive/12971
Add support for sftp custom port
Diffstat (limited to 'apps/files_external/lib/sftp.php')
-rw-r--r-- | apps/files_external/lib/sftp.php | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 82dfc87501c..edf39244773 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -37,6 +37,7 @@ class SFTP extends \OC\Files\Storage\Common { private $user; private $password; private $root; + private $port = 22; /** * @var \Net_SFTP @@ -50,10 +51,21 @@ class SFTP extends \OC\Files\Storage\Common { \Net_SFTP_Stream::register(); $this->host = $params['host']; + + //deals with sftp://server example $proto = strpos($this->host, '://'); if ($proto != false) { $this->host = substr($this->host, $proto+3); } + + //deals with server:port + $hasPort = strpos($this->host,':'); + if($hasPort != false) { + $pieces = explode(":", $this->host); + $this->host = $pieces[0]; + $this->port = $pieces[1]; + } + $this->user = $params['user']; $this->password = isset($params['password']) ? $params['password'] : ''; @@ -81,7 +93,7 @@ class SFTP extends \OC\Files\Storage\Common { } $hostKeys = $this->readHostKeys(); - $this->client = new \Net_SFTP($this->host); + $this->client = new \Net_SFTP($this->host, $this->port); // The SSH Host Key MUST be verified before login(). $currentHostKey = $this->client->getServerPublicHostKey(); @@ -112,7 +124,7 @@ class SFTP extends \OC\Files\Storage\Common { } public function getId(){ - return 'sftp::' . $this->user . '@' . $this->host . '/' . $this->root; + return 'sftp::' . $this->user . '@' . $this->host . ':' . $this->port . '/' . $this->root; } public function getHost() { @@ -342,7 +354,7 @@ class SFTP extends \OC\Files\Storage\Common { // Do not pass the password here. We want to use the Net_SFTP object // supplied via stream context or fail. We only supply username and // hostname because this might show up in logs (they are not used). - $url = 'sftp://'.$this->user.'@'.$this->host.$this->root.$path; + $url = 'sftp://'.$this->user.'@'.$this->host.':'.$this->port.$this->root.$path; return $url; } } |