diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index 125888ef72237e40bf281009ca315b61d62a9614..ed8f980fea24519ff24785b778f9be643399f704 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -76,7 +76,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 f6b2873cf49a460c6c774e7238c90eb4a74842b7..fc55e800a89c26ebc06a5bfe9c6f85b5c3d0958b 100644
--- a/apps/files_external/lib/sftp.php
+++ b/apps/files_external/lib/sftp.php
@@ -459,7 +459,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;
 	}
 }