summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2006-11-24 15:47:45 +0000
committerNuno Lopes <nlopess@php.net>2006-11-24 15:47:45 +0000
commitd64b17543cfa5e171ca493eb3581eea0acd42dba (patch)
treed12e15b9bd1f7cd9df672ab437a016908f6a83fd /ext/ftp
parent050e32ed65e3f479e6af88cf5ed9f88c158af0dd (diff)
downloadphp-git-d64b17543cfa5e171ca493eb3581eea0acd42dba.tar.gz
fix tests after Tony's commit and add a test for the bug he fixed
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/tests/005.phpt22
-rw-r--r--ext/ftp/tests/bug39583-2.phpt34
-rw-r--r--ext/ftp/tests/bug39583.phpt34
-rw-r--r--ext/ftp/tests/bug7216-2.phpt6
-rw-r--r--ext/ftp/tests/server.inc39
5 files changed, 120 insertions, 15 deletions
diff --git a/ext/ftp/tests/005.phpt b/ext/ftp/tests/005.phpt
index 4291c1c1bd..bbc11e87ae 100644
--- a/ext/ftp/tests/005.phpt
+++ b/ext/ftp/tests/005.phpt
@@ -53,34 +53,34 @@ bool(false)
Warning: ftp_exec(): Command not implemented (5). in %s005.php on line 15
bool(false)
-Warning: ftp_fget(): Command not implemented (6). in %s005.php on line 16
+Warning: ftp_fget(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 16
bool(false)
-Warning: ftp_fput(): Command not implemented (7). in %s005.php on line 17
+Warning: ftp_fput(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 17
bool(false)
-Warning: ftp_get(): Command not implemented (8). in %s005.php on line 18
+Warning: ftp_get(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 18
bool(false)
int(-1)
-Warning: ftp_mkdir(): Command not implemented (10). in %s005.php on line 20
+Warning: ftp_mkdir(): Command not implemented (7). in %s005.php on line 20
bool(false)
Warning: ftp_nb_continue(): no nbronous transfer to continue. in %s005.php on line 21
int(0)
-Warning: ftp_nb_fget(): Command not implemented (11). in %s005.php on line 22
-int(0)
+Warning: ftp_nb_fget(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 22
+bool(false)
-Warning: ftp_nb_fput(): Command not implemented (12). in %s005.php on line 23
-int(0)
+Warning: ftp_nb_fput(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 23
+bool(false)
-Warning: ftp_systype(): Command not implemented (13). in %s005.php on line 24
+Warning: ftp_systype(): Command not implemented (8). in %s005.php on line 24
bool(false)
-Warning: ftp_pwd(): Command not implemented (14). in %s005.php on line 25
+Warning: ftp_pwd(): Command not implemented (9). in %s005.php on line 25
bool(false)
int(-1)
-Warning: ftp_rmdir(): Command not implemented (16). in %s005.php on line 27
+Warning: ftp_rmdir(): Command not implemented (11). in %s005.php on line 27
bool(false)
diff --git a/ext/ftp/tests/bug39583-2.phpt b/ext/ftp/tests/bug39583-2.phpt
new file mode 100644
index 0000000000..44921b3205
--- /dev/null
+++ b/ext/ftp/tests/bug39583-2.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #39583: FTP always transfers in binary mode
+--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'));
+
+$source_file = __FILE__;
+$destination_file = basename(__FILE__);
+
+// upload the file
+$upload = ftp_put($ftp, $destination_file, $source_file, FTP_BINARY);
+
+// check upload status
+if (!$upload) {
+ echo "FTP upload has failed!";
+ } else {
+ echo "Uploaded $source_file as $destination_file";
+ }
+
+// close the FTP stream
+ftp_close($ftp);
+?>
+--EXPECTF--
+bool(true)
+Uploaded %sbug39583-2.php as bug39583-2.php
diff --git a/ext/ftp/tests/bug39583.phpt b/ext/ftp/tests/bug39583.phpt
new file mode 100644
index 0000000000..47d9e30802
--- /dev/null
+++ b/ext/ftp/tests/bug39583.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #39583: FTP always transfers in binary mode
+--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'));
+
+$source_file = __FILE__;
+$destination_file = basename(__FILE__);
+
+// upload the file
+$upload = ftp_put($ftp, $destination_file, $source_file, FTP_ASCII);
+
+// check upload status
+if (!$upload) {
+ echo "FTP upload has failed!";
+ } else {
+ echo "Uploaded $source_file as $destination_file";
+ }
+
+// close the FTP stream
+ftp_close($ftp);
+?>
+--EXPECTF--
+bool(true)
+Uploaded %sbug39583.php as bug39583.php
diff --git a/ext/ftp/tests/bug7216-2.phpt b/ext/ftp/tests/bug7216-2.phpt
index ce31c45ab5..62b6ec84bf 100644
--- a/ext/ftp/tests/bug7216-2.phpt
+++ b/ext/ftp/tests/bug7216-2.phpt
@@ -16,6 +16,6 @@ var_dump(ftp_login($ftp, 'anonymous', 'IEUser@'));
var_dump(ftp_mkdir($ftp, 'CVS'));
?>
---EXPECTREGEX--
-bool\(true\)
-string\(\d+\) ".+[\/\\]CVS"
+--EXPECT--
+bool(true)
+string(20) "/path/to/ftproot/CVS"
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)) {