From d64b17543cfa5e171ca493eb3581eea0acd42dba Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Fri, 24 Nov 2006 15:47:45 +0000 Subject: fix tests after Tony's commit and add a test for the bug he fixed --- ext/ftp/tests/server.inc | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'ext/ftp/tests/server.inc') diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 37df793375..c2eef56980 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -157,9 +157,46 @@ while($buf = fread($s, 4098)) { fputs($s, "215 UNIX Type: L8.\r\n"); } + } elseif ($buf === "TYPE A\r\n") { + $ascii = true; + fputs($s, "200 OK\r\n"); + + } elseif ($buf === "TYPE I\r\n") { + $ascii = false; + fputs($s, "200 OK\r\n"); + } elseif ($buf === "QUIT\r\n") { break; + } elseif (preg_match("~^PORT (\d+),(\d+),(\d+),(\d+),(\d+),(\d+)\r\n$~", $buf, $m)) { + $host = "$m[1].$m[2].$m[3].$m[4]"; + $port = ((int)$m[5] << 8) + (int)$m[6]; + fputs($s, "200 OK.\r\n"); + + } elseif (preg_match("~^STOR ([\w/.-]+)\r\n$~", $buf, $m)) { + 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; + } + + $data = stream_get_contents($fs); + $orig = file_get_contents(dirname(__FILE__).'/'.$m[1]); + + if (isset($ascii) && !$ascii && $orig === $data) { + fputs($s, "226 Closing data Connection.\r\n"); + + } elseif (!empty($ascii) && $data === strtr($orig, array("\r\n" => "\n", "\r" => "\n", "\n" => "\r\n"))) { + fputs($s, "226 Closing data Connection.\r\n"); + + } else { + var_dump($data); + var_dump($orig); + fputs($s, "552 Requested file action aborted.\r\n"); + } + fclose($fs); + } elseif (preg_match("~^CWD ([A-Za-z./]+)\r\n$~", $buf, $m)) { change_dir($m[1]); fputs($s, "250 CWD command successful.\r\n"); @@ -168,7 +205,7 @@ while($buf = fread($s, 4098)) { if (isset($bug7216)) { fputs($s, "257 OK.\r\n"); } else { - fputs($s, '257 "'.realpath($m[1])."\" created.\r\n"); + fputs($s, "257 \"/path/to/ftproot$cwd$m[1]\" created.\r\n"); } } elseif (preg_match('/^USER /', $buf)) { -- cgit v1.2.1