diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index 338e2c14fa4c706c0d118097ff92387a6799fbb8..7249aeceb5d9250cffbc74311423bd1df6e672ae 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -78,7 +78,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
 		if ($this->secure) {
 			$url.='s';
 		}
-		$url.='://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path;
+		$url.='://'.urlencode($this->user).':'.urlencode($this->password).'@'.$this->host.$this->root.$path;
 		return $url;
 	}
 
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php
index c44ee9f908e0a7a5a098b58fd19c21f79f7a697a..a6984f3b4e0e0fbf10169538be0feea43b8f569d 100644
--- a/apps/files_external/lib/sftp.php
+++ b/apps/files_external/lib/sftp.php
@@ -461,7 +461,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->port.$this->root.$path;
+		$url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path;
 		return $url;
 	}
 }