diff options
author | Andreas Treichel <gmblar+github@gmail.com> | 2017-01-28 04:20:40 +0100 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2017-01-29 07:28:22 +0000 |
commit | 0103d1e3bc7b3861a2bff81de204eceb3f4c212a (patch) | |
tree | 943bce4f797f3643824cbf6dda05edf7da524b11 /ext/ftp/tests/server.inc | |
parent | 3de7b2ab523947de3cf85e230a242b1af884641a (diff) | |
download | php-git-0103d1e3bc7b3861a2bff81de204eceb3f4c212a.tar.gz |
FTP: implement MLSD for structured listing of directories, decribed at https://tools.ietf.org/html/rfc3659
Diffstat (limited to 'ext/ftp/tests/server.inc')
-rw-r--r-- | ext/ftp/tests/server.inc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index ffef025074..1ae52f05b6 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -441,6 +441,44 @@ if ($pid) { fputs($s, "350 OK\r\n"); }elseif (preg_match('/^SIZE largefile/', $buf)) { fputs($s, "213 5368709120\r\n"); + }elseif (preg_match('/^MLSD no_exists\//', $buf, $matches)) { + fputs($s, "425 Error establishing connection\r\n"); + }elseif (preg_match("~^MLSD(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) { + + if(isset($m[1]) && (($m[1] === 'bogusdir') || ($m[1] === '/bogusdir'))) { + fputs($s, "250 $m[1]: No such file or directory\r\n"); + continue; + } + + // there are some servers that don't open the ftp-data socket if there's nothing to send + if(isset($bug39458) && isset($m[1]) && $m[1] === 'emptydir') { + fputs($s, "226 Transfer complete.\r\n"); + continue; + } + + if(empty($pasv)) { + fputs($s, "150 File status okay; about to open data connection\r\n"); + if(!$fs = stream_socket_client("tcp://$host:$port")) { + fputs($s, "425 Can't open data connection\r\n"); + continue; + } + } else { + fputs($s, "125 Data connection already open; transfer starting.\r\n"); + $fs = $pasvs; + } + + if((!empty($ssl)) && (!stream_socket_enable_crypto($pasvs, TRUE, STREAM_CRYPTO_METHOD_SSLv23_SERVER))) { + die("SSLv23 handshake failed.\n"); + } + + if(empty($m[1]) || $m[1] !== 'emptydir') { + fputs($fs, "modify=20170127230002;perm=flcdmpe;type=cdir;unique=811U4340002;UNIX.group=33;UNIX.mode=0755;UNIX.owner=33; .\r\n"); + fputs($fs, "modify=20170127230002;perm=flcdmpe;type=pdir;unique=811U4340002;UNIX.group=33;UNIX.mode=0755;UNIX.owner=33; ..\r\n"); + fputs($fs, "modify=20170126121225;perm=adfrw;size=4729;type=file;unique=811U4340CB9;UNIX.group=33;UNIX.mode=0644;UNIX.owner=33; foobar\r\n"); + } + + fputs($s, "226 Closing data Connection.\r\n"); + fclose($fs); }else { fputs($s, "500 Syntax error, command unrecognized.\r\n"); dump_and_exit($buf); |