phpBB

Code Changes

File: includes/functions_transfer.php

  Unmodified   Added   Modified   Removed
Line 206Line 206
		$directory = $this->root_path . str_replace($phpbb_root_path, '', $directory);

$this->_chdir($directory);

		$directory = $this->root_path . str_replace($phpbb_root_path, '', $directory);

$this->_chdir($directory);

		$result = $this->_ls('');

		$result = $this->_ls();


if ($result !== false && is_array($result))
{


if ($result !== false && is_array($result))
{

Line 315Line 315
		{
return 'ERR_CONNECTING_SERVER';
}

		{
return 'ERR_CONNECTING_SERVER';
}


// attempt to turn pasv mode on
@ftp_pasv($this->connection, true);

 

// login to the server
if (!@ftp_login($this->connection, $this->username, $this->password))
{
return 'ERR_UNABLE_TO_LOGIN';
}


// login to the server
if (!@ftp_login($this->connection, $this->username, $this->password))
{
return 'ERR_UNABLE_TO_LOGIN';
}

 

// attempt to turn pasv mode on
@ftp_pasv($this->connection, true);


// change to the root directory
if (!$this->_chdir($this->root_path))


// change to the root directory
if (!$this->_chdir($this->root_path))

Line 460Line 460
	*/
function _ls($dir = './')
{

	*/
function _ls($dir = './')
{

		return @ftp_nlist($this->connection, $dir);
































		$list = @ftp_nlist($this->connection, $dir);

// See bug #46295 - Some FTP daemons don't like './'
if ($dir === './')
{
// Let's try some alternatives
$list = (empty($list)) ? @ftp_nlist($this->connection, '.') : $list;
$list = (empty($list)) ? @ftp_nlist($this->connection, '') : $list;
}

// Return on error
if ($list === false)
{
return false;
}

// Remove path if prepended
foreach ($list as $key => $item)
{
// Use same separator for item and dir
$item = str_replace('\\', '/', $item);
$dir = str_replace('\\', '/', $dir);

if (!empty($dir) && strpos($item, $dir) === 0)
{
$item = substr($item, strlen($dir));
}

$list[$key] = $item;
}

return $list;

	}

/**

	}

/**

Line 706Line 737
		$list = array();
while (!@feof($this->data_connection))
{

		$list = array();
while (!@feof($this->data_connection))
{

			$list[] = preg_replace('#[\r\n]#', '', @fgets($this->data_connection, 512));






			$filename = preg_replace('#[\r\n]#', '', @fgets($this->data_connection, 512));

if ($filename !== '')
{
$list[] = $filename;
}

		}
$this->_close_data_connection();

		}
$this->_close_data_connection();

 

// Clear buffer
$this->_check_command();

// See bug #46295 - Some FTP daemons don't like './'
if ($dir === './' && empty($list))
{
// Let's try some alternatives
$list = $this->_ls('.');

if (empty($list))
{
$list = $this->_ls('');
}

return $list;
}

// Remove path if prepended
foreach ($list as $key => $item)
{
// Use same separator for item and dir
$item = str_replace('\\', '/', $item);
$dir = str_replace('\\', '/', $dir);

if (!empty($dir) && strpos($item, $dir) === 0)
{
$item = substr($item, strlen($dir));
}

$list[$key] = $item;
}


return $list;
}


return $list;
}

Line 740Line 808
	*/
function _open_data_connection()
{

	*/
function _open_data_connection()
{

 
		// Try to find out whether we have a IPv4 or IPv6 (control) connection
if (function_exists('stream_socket_get_name'))
{
$socket_name = stream_socket_get_name($this->connection, true);
$server_ip = substr($socket_name, 0, strrpos($socket_name, ':'));
}

if (!isset($server_ip) || preg_match(get_preg_expression('ipv4'), $server_ip))
{
// Passive mode

		$this->_send_command('PASV', '', false);

if (!$ip_port = $this->_check_command(true))

		$this->_send_command('PASV', '', false);

if (!$ip_port = $this->_check_command(true))

Line 757Line 835
		$temp = explode(',', $temp[0]);
$server_ip = $temp[0] . '.' . $temp[1] . '.' . $temp[2] . '.' . $temp[3];
$server_port = $temp[4] * 256 + $temp[5];

		$temp = explode(',', $temp[0]);
$server_ip = $temp[0] . '.' . $temp[1] . '.' . $temp[2] . '.' . $temp[3];
$server_port = $temp[4] * 256 + $temp[5];

 
		}
else
{
// Extended Passive Mode - RFC2428
$this->_send_command('EPSV', '', false);

if (!$epsv_response = $this->_check_command(true))
{
return false;
}

// Response looks like "229 Entering Extended Passive Mode (|||12345|)"
// where 12345 is the tcp port for the data connection
if (!preg_match('#\(\|\|\|([0-9]+)\|\)#', $epsv_response, $match))
{
return false;
}
$server_port = (int) $match[1];

// fsockopen expects IPv6 address in square brackets
$server_ip = "[$server_ip]";
}


		$errno = 0;
$errstr = '';


		$errno = 0;
$errstr = '';


Line 791Line 892
			$result = @fgets($this->connection, 512);
$response .= $result;
}

			$result = @fgets($this->connection, 512);
$response .= $result;
}

		while (substr($response, 3, 1) != ' ');

		while (substr($result, 3, 1) !== ' ');


if (!preg_match('#^[123]#', $response))
{


if (!preg_match('#^[123]#', $response))
{