From 3fff9483213f215c90d556e0862143f4fc5d66ef Mon Sep 17 00:00:00 2001 From: Zoe Slattery Date: Wed, 17 Dec 2008 12:35:53 +0000 Subject: [PATCH] New FTP test from Nathaniel McHugh --- ext/ftp/tests/ftp_get_basic.phpt | 39 ++++++++++++++++++++++++++++++++ ext/ftp/tests/server.inc | 25 ++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 ext/ftp/tests/ftp_get_basic.phpt diff --git a/ext/ftp/tests/ftp_get_basic.phpt b/ext/ftp/tests/ftp_get_basic.phpt new file mode 100644 index 0000000000..9e2dfb0349 --- /dev/null +++ b/ext/ftp/tests/ftp_get_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +FTP ftp_get file for both binary and ASCII transfer modes +--CREDITS-- +Nathaniel McHugh +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +bool(true) +For sale: baby shoes, never worn. +bool(true) +string(21) "BINARYFoo%00Bar%0D%0A" + +Warning: ftp_get(): a warning: No such file or directory in %sftp_get_basic.php on line %d diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index bf11257af0..76198c23d0 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -136,7 +136,6 @@ $cwd = '/'; $num_bogus_cmds = 0; while($buf = fread($s, 4098)) { - if (!empty($bogus)) { fputs($s, "502 Command not implemented (".$num_bogus_cmds++.").\r\n"); @@ -262,7 +261,29 @@ while($buf = fread($s, 4098)) { fputs($s, "550 No file named \"{$matches [1]}\"\r\n"); break; } - } + }elseif (preg_match('/^RETR ([\w\h]+)/', $buf, $matches)) { + if (!$fs = stream_socket_client("tcp://$host:$port")) { + fputs($s, "425 Can't open data connection\r\n"); + continue; + } + switch($matches[1]){ + case "a story": + fputs($s, "150 File status okay; about to open data connection.\r\n"); + fputs($fs, "For sale: baby shoes, never worn.\r\n"); + fputs($s, "226 Closing data Connection.\r\n"); + break; + case "binary data": + fputs($s, "150 File status okay; about to open data connection.\r\n"); + $transfer_type = $ascii? 'ASCII' : 'BINARY' ; + fputs($fs, $transfer_type."Foo\0Bar\r\n"); + fputs($s, "226 Closing data Connection.\r\n"); + break; + default: + fputs($s, "550 {$matches[1]}: No such file or directory \r\n"); + break; + } + fclose($fs); + } else { fputs($s, "500 Syntax error, command unrecognized.\r\n"); dump_and_exit($buf); -- 2.40.0