protected function _ftp_($engineOptions)
{
$config = Connect_Helper_StorageOptions::getFtpConfig($engineOptions);
if (is_array(self::$_onHoldions)) {
$onHoldKey = md5($config['host'] . $config['port'] . $config['username']);
if (!empty(self::$_onHoldions[Connect_Option::MODE_FTP][$onHoldKey])) {
return self::$_onHoldions[Connect_Option::MODE_FTP][$onHoldKey];
}
}
if (!function_exists('ftp_')) {
throw new XenForo_Exception('PHP does not have FTP support enabled');
}
if (empty($config['host'])) {
throw new XenForo_Exception('FTP host cannot be empty');
}
$ion = @ftp_($config['host'], $config['port']);
if (empty($ion)) {
throw new XenForo_Exception(sprintf('Unable to to %s:%d', $config['host'], $config['port']));
}
if (!empty($config['username']) && !empty($config['password'])) {
$loggedIn = @ftp_login($ion, $config['username'], $config['password']);
if (!$loggedIn) {
throw new XenForo_Exception(sprintf(
'Unable to login to %s (user=%s)',
$config['host'],
$config['username']
));
}
}
if ($config['passive']) {
$passiveModeOk = @ftp_pasv($ion, true);
if (!$passiveModeOk) {
throw new XenForo_Exception(sprintf('Unable to switch to passive mode for %s', $config['host']));
}
}
if (is_array(self::$_onHoldions)
&& !empty($onHoldKey)
) {
self::$_onHoldions[Connect_Option::MODE_FTP][$onHoldKey] = $ion;
}
return $ion;
}
protected function _ftp_close($ion)
{
if (empty($ion)) {
return true;
}
if (is_array(self::$_onHoldions)) {
return true;
}
return @ftp_close($ion);
}
protected function _ftp_mkdirs($ion, $dirPath)
{
$parts = explode('/', $dirPath);
$missingParts = array();
$existingPath = false;
while (!empty($parts)) {
$checkingPath = implode('/', $parts);
if (empty($checkingPath)) {
$checkingPath = '/';
}
if (@ftp_chdir($ion, $checkingPath)) {
$existingPath = $checkingPath;
break;
}