From 211104efaa91d12a85e2916d35c10575e9507bb0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 12 Feb 2025 12:08:19 +0100 Subject: [PATCH] wip #7328 @0.5 --- src/CommandLine/CloneProgram.php | 6 +++--- src/CommandLine/LFTP.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/CommandLine/CloneProgram.php b/src/CommandLine/CloneProgram.php index 1791114..171bfca 100644 --- a/src/CommandLine/CloneProgram.php +++ b/src/CommandLine/CloneProgram.php @@ -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) diff --git a/src/CommandLine/LFTP.php b/src/CommandLine/LFTP.php index dffa3b1..6978385 100644 --- a/src/CommandLine/LFTP.php +++ b/src/CommandLine/LFTP.php @@ -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); + } /** -- 2.39.5