zoe             Wed Dec 17 12:34:50 2008 UTC

  Added files:                 
    /php-src/ext/ftp/tests      ftp_get_basic.phpt 

  Modified files:              
    /php-src/ext/ftp/tests      server.inc 
  Log:
  New FTP test from Nathaniel McHugh
  
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/server.inc?r1=1.9&r2=1.10&diff_format=u
Index: php-src/ext/ftp/tests/server.inc
diff -u php-src/ext/ftp/tests/server.inc:1.9 
php-src/ext/ftp/tests/server.inc:1.10
--- php-src/ext/ftp/tests/server.inc:1.9        Fri Dec  5 16:27:41 2008
+++ php-src/ext/ftp/tests/server.inc    Wed Dec 17 12:34:49 2008
@@ -136,7 +136,6 @@
 $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 @@
                                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);

http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/ftp_get_basic.phpt?view=markup&rev=1.1
Index: php-src/ext/ftp/tests/ftp_get_basic.phpt
+++ php-src/ext/ftp/tests/ftp_get_basic.phpt
--TEST--
FTP ftp_get file for both binary and ASCII transfer modes 
--XFAIL--
Missing implementation in PHP6
--CREDITS--
Nathaniel McHugh
--SKIPIF--
<?php
require 'skipif.inc';
?>
--FILE--
<?php
require 'server.inc';

$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) die("Couldn't connect to the server");

var_dump(ftp_login($ftp, 'user', 'pass'));

//test simple text transfer
$tmpfname = tempnam(".", "ftp_test");
var_dump(ftp_get($ftp, $tmpfname ,'a story.txt', FTP_ASCII));
echo file_get_contents($tmpfname);

//test binary data transfer
$tmpfname = tempnam(".", "ftp_test");
var_dump(ftp_get($ftp, $tmpfname, 'binary data.bin', FTP_BINARY));
var_dump(urlencode(file_get_contents($tmpfname)));
unlink($tmpfname);

//test non-existant file request 
ftp_get($ftp, $tmpfname ,'a warning.txt', FTP_ASCII);
?>
--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



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to