diff --git a/lib/Alchemy/Phrasea/Core/Provider/FtpServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/FtpServiceProvider.php
index 42e9acf169..db6ad0470f 100644
--- a/lib/Alchemy/Phrasea/Core/Provider/FtpServiceProvider.php
+++ b/lib/Alchemy/Phrasea/Core/Provider/FtpServiceProvider.php
@@ -21,9 +21,11 @@ class FtpServiceProvider implements ServiceProviderInterface
*/
public function register(Application $app)
{
- $app['phraseanet.ftp.client'] = $app->protect(function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) {
- return new \ftpclient($host, $port, $timeout, $ssl, $proxy, $proxyport);
- });
+ $app['phraseanet.ftp.client'] = $app->protect(
+ function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false, $proxyuser = false, $proxypwd = false) {
+ return new \ftpclient($host, $port, $timeout, $ssl, $proxy, $proxyport, $proxyuser, $proxypwd);
+ }
+ );
}
/**
diff --git a/lib/Alchemy/Phrasea/TaskManager/Editor/FtpEditor.php b/lib/Alchemy/Phrasea/TaskManager/Editor/FtpEditor.php
index fd1cf4c7af..f081103ba8 100644
--- a/lib/Alchemy/Phrasea/TaskManager/Editor/FtpEditor.php
+++ b/lib/Alchemy/Phrasea/TaskManager/Editor/FtpEditor.php
@@ -41,6 +41,8 @@ class FtpEditor extends AbstractEditor
";
-
- if ($this->debug && $proxyport)
- echo "Utilisation du port proxy $proxyport\n
";
-
- $this->proxy = $proxy;
+ public function __construct($host, $port = 21, $timeout = 90, $ssl = false,
+ $proxyhost = false,
+ $proxyport = false,
+ $proxyuser = false,
+ $proxypwd = false
+ )
+ {
$this->host = $host;
+ $this->port = $port;
+ $this->proxyhost = $proxyhost;
+ $this->proxyport = $proxyport;
+ $this->proxyuser = $proxyuser;
+ $this->proxypwd = $proxypwd;
+
+ // if there is a proxy, connect to it, not on host/port provided
+ $host = $proxyhost ? $proxyhost : $host;
+ $port = $proxyport ? $proxyport : $port;
+ // clean the addr, force ssl if needed
+ $host = $this->cleanAddr($host, $ssl);
if ($this->debug)
- echo "Ouverture de connection vers $host:$port timeout $timeout et proxy $proxy:$proxyport\n
";
-
- if (trim($host) == '') {
- throw new Exception('Nom d\'hote incorrect ' . $host);
- }
+ echo "Ouverture de connection vers $host:$port timeout $timeout\n
";
try {
if ($ssl === true) {
@@ -72,22 +89,29 @@ class ftpclient
public function login($username, $password)
{
- $username = $this->proxy ? $username . "@" . $this->host : $username;
+ if($this->proxyhost) {
+ $username .= ("@" . $this->host);
+ if ($this->proxyuser) {
+ $username .= (' ' . $this->proxyuser);
+ }
+ }
$retry = 3;
$done = false;
- if ($this->debug)
- echo "tentative de login avec $username, $password\n
";
-
- while ($retry > 0) {
- if ((@ftp_login($this->connexion, $username, $password)) === false) {
- $retry --;
- } else {
- $retry = 0;
+ while (!$done && $retry-- > 0) {
+ $ret = ftp_raw($this->connexion, "USER ".$username);
+ if(is_array($ret) && $password) {
+ $ret = ftp_raw($this->connexion, "PASS ".$password);
+ }
+ if(is_array($ret) && $this->proxypwd) {
+ $ret = ftp_raw($this->connexion, "ACCT ".$this->proxypwd);
+ }
+ if(is_array($ret)) {
$done = true;
}
}
+
if (! $done) {
throw new Exception('Impossible de s\'authentifier sur le serveur FTP');
}
diff --git a/templates/web/admin/task-manager/task-editor/ftp.html.twig b/templates/web/admin/task-manager/task-editor/ftp.html.twig
index 49f6920a1b..da5f5c757a 100644
--- a/templates/web/admin/task-manager/task-editor/ftp.html.twig
+++ b/templates/web/admin/task-manager/task-editor/ftp.html.twig
@@ -7,12 +7,26 @@
-