$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)
{
protected $_prog = '/usr/bin/lftp';
+ protected $_ftpTimeout = 15;
+
/**
* @var bool
*/
}
}
+ /**
+ * @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')
];
$filename = explode('/', $this->getSrc());
$filename = end($filename);
$commands = array_merge($commands, [
+ 'mkdir -p ' . $this->getFinalDest(),
+ 'cd ' . $this->getFinalDest(),
'put ' . $this->getSrc()
]);
if ($this->isDryRun()) {
}
}
- $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);
+
}
/**