]> _ Git - cubist_util.git/commitdiff
wip #7328 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Feb 2025 11:08:19 +0000 (12:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Feb 2025 11:08:19 +0000 (12:08 +0100)
src/CommandLine/CloneProgram.php
src/CommandLine/LFTP.php

index 1791114169b8846fdd3725a737646461da0eef4e..171bfca397a5183743372265e344f8c675989fe9 100644 (file)
@@ -129,11 +129,11 @@ class CloneProgram extends CommandLine
         $res = '';
         if ($base) {
             $res .= $base . '/';
-            $res .= ltrim($this->getDest() . '/');
+            $res .= ltrim(rtrim($this->getDest(), '/') . '/');
         } else {
-            $res .= $this->getDest();
+            $res .= rtrim($this->getDest(), '/') . '/';
         }
-        return $res;
+        return str_replace('//', '/', $res);
     }
 
     public function setCloneArg($name, $value = null)
index dffa3b12084e27efd2b571a528f3dff49ed3362b..6978385496cc2e7b155e6a7569b9a4a395a64173 100644 (file)
@@ -9,6 +9,8 @@ class LFTP extends CloneUserpassProgram
 {
     protected $_prog = '/usr/bin/lftp';
 
+    protected $_ftpTimeout = 15;
+
     /**
      * @var bool
      */
@@ -24,12 +26,29 @@ class LFTP extends CloneUserpassProgram
         }
     }
 
+    /**
+     * @param int $ftpTimeout
+     */
+    public function setFTPTimeout(int $ftpTimeout): void
+    {
+        $this->_ftpTimeout = $ftpTimeout;
+    }
+
+    /**
+     * @return int
+     */
+    public function getFTPTimeout(): int
+    {
+        return $this->_ftpTimeout;
+    }
+
 
     protected function _preExecute()
     {
         parent::_preExecute();
         $commands = [
             'set net:reconnect-interval-base 5',
+            'set net:timeout ' . $this->getFTPTimeout(),
             'set net:max-retries 2',
             'set ftp:passive-mode ' . ($this->isPassiveMode() ? '1' : '0')
         ];
@@ -72,6 +91,8 @@ class LFTP extends CloneUserpassProgram
             $filename = explode('/', $this->getSrc());
             $filename = end($filename);
             $commands = array_merge($commands, [
+                'mkdir -p ' . $this->getFinalDest(),
+                'cd ' . $this->getFinalDest(),
                 'put ' . $this->getSrc()
             ]);
             if ($this->isDryRun()) {
@@ -79,7 +100,15 @@ class LFTP extends CloneUserpassProgram
             }
         }
 
-        $this->setArg('c', 'open ftp://' . $this->getUsername() . ':' . $this->getPassword() . '@' . $this->getHost() . ':' . $this->getPort() . ' ' . implode(';', $commands));
+        $this->setArg('c', 'open ' . $this->getUsername() . ':' . $this->_escapePassword($this->getPassword()) . '@' . $this->getHost() . ':' . $this->getPort() . ' ' . implode(';', $commands));
+    }
+
+    protected function _escapePassword($password)
+    {
+        return preg_replace_callback('/[^a-zA-Z0-9]/', function ($matches) {
+            return '%' . strtoupper(dechex(ord($matches[0])));
+        }, $password);
+
     }
 
     /**