aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_transfer.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-08-10 16:14:45 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-08-11 23:15:25 +0200
commit66553fb8574a9d2578f423f4db0461efe49ea099 (patch)
tree637341925f44bd38352aadece482bb21906f626d /phpBB/includes/functions_transfer.php
parentec3f4db4254783a8542da5ed479949cee7a98454 (diff)
downloadforums-66553fb8574a9d2578f423f4db0461efe49ea099.tar
forums-66553fb8574a9d2578f423f4db0461efe49ea099.tar.gz
forums-66553fb8574a9d2578f423f4db0461efe49ea099.tar.bz2
forums-66553fb8574a9d2578f423f4db0461efe49ea099.tar.xz
forums-66553fb8574a9d2578f423f4db0461efe49ea099.zip
[ticket/9297] Add support for Extended Passive Mode (EPSV) in ftp_fsock class.
PHPBB3-9297
Diffstat (limited to 'phpBB/includes/functions_transfer.php')
-rw-r--r--phpBB/includes/functions_transfer.php55
1 files changed, 44 insertions, 11 deletions
diff --git a/phpBB/includes/functions_transfer.php b/phpBB/includes/functions_transfer.php
index 046abede8e..5ab7a87efd 100644
--- a/phpBB/includes/functions_transfer.php
+++ b/phpBB/includes/functions_transfer.php
@@ -808,23 +808,56 @@ class ftp_fsock extends transfer
*/
function _open_data_connection()
{
- $this->_send_command('PASV', '', false);
-
- if (!$ip_port = $this->_check_command(true))
+ // Try to find out whether we have a IPv4 or IPv6 (control) connection
+ if (function_exists('stream_socket_get_name'))
{
- return false;
+ $socket_name = stream_socket_get_name($this->connection, true);
+ $server_ip = substr($socket_name, 0, strrpos($socket_name, ':'));
}
- // open the connection to start sending the file
- if (!preg_match('#[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+#', $ip_port, $temp))
+ if (!isset($server_ip) || preg_match(get_preg_expression('ipv4'), $server_ip))
{
- // bad ip and port
- return false;
+ // Passive mode
+ $this->_send_command('PASV', '', false);
+
+ if (!$ip_port = $this->_check_command(true))
+ {
+ return false;
+ }
+
+ // open the connection to start sending the file
+ if (!preg_match('#[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+#', $ip_port, $temp))
+ {
+ // bad ip and port
+ return false;
+ }
+
+ $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]";
}
- $temp = explode(',', $temp[0]);
- $server_ip = $temp[0] . '.' . $temp[1] . '.' . $temp[2] . '.' . $temp[3];
- $server_port = $temp[4] * 256 + $temp[5];
$errno = 0;
$errstr = '';