summaryrefslogtreecommitdiff
path: root/ext/ftp/tests
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
commit2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch)
tree41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/ftp/tests
parentd29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff)
downloadphp-2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b.tar.gz
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/ftp/tests')
-rw-r--r--ext/ftp/tests/001.phpt36
-rw-r--r--ext/ftp/tests/002.phpt38
-rw-r--r--ext/ftp/tests/003.phpt43
-rw-r--r--ext/ftp/tests/004.phpt79
-rw-r--r--ext/ftp/tests/005.phpt86
-rw-r--r--ext/ftp/tests/006.phpt100
-rw-r--r--ext/ftp/tests/bug27809.phpt21
-rw-r--r--ext/ftp/tests/bug37799.phpt22
-rw-r--r--ext/ftp/tests/bug39458-2.phpt36
-rw-r--r--ext/ftp/tests/bug39458.phpt35
-rw-r--r--ext/ftp/tests/bug39583-2.phpt34
-rw-r--r--ext/ftp/tests/bug39583.phpt35
-rw-r--r--ext/ftp/tests/bug7216-2.phpt21
-rw-r--r--ext/ftp/tests/bug7216.phpt21
-rw-r--r--ext/ftp/tests/cert.pem48
-rw-r--r--ext/ftp/tests/server.inc258
-rw-r--r--ext/ftp/tests/skipif.inc5
17 files changed, 918 insertions, 0 deletions
diff --git a/ext/ftp/tests/001.phpt b/ext/ftp/tests/001.phpt
new file mode 100644
index 000000000..38475d3ff
--- /dev/null
+++ b/ext/ftp/tests/001.phpt
@@ -0,0 +1,36 @@
+--TEST--
+FTP login
+--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'));
+var_dump(ftp_raw($ftp, 'HELP'));
+var_dump(ftp_raw($ftp, 'HELP HELP'));
+
+var_dump(ftp_close($ftp));
+?>
+--EXPECT--
+bool(true)
+array(4) {
+ [0]=>
+ string(55) "214-There is help available for the following commands:"
+ [1]=>
+ string(5) " USER"
+ [2]=>
+ string(5) " HELP"
+ [3]=>
+ string(15) "214 end of list"
+}
+array(1) {
+ [0]=>
+ string(39) "214 Syntax: HELP [<SP> <string>] <CRLF>"
+}
+bool(true)
diff --git a/ext/ftp/tests/002.phpt b/ext/ftp/tests/002.phpt
new file mode 100644
index 000000000..e27113f61
--- /dev/null
+++ b/ext/ftp/tests/002.phpt
@@ -0,0 +1,38 @@
+--TEST--
+FTP login (SSL)
+--SKIPIF--
+<?php
+$ssl = 1;
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$ssl = 1;
+require 'server.inc';
+
+$ftp = ftp_ssl_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+var_dump(ftp_raw($ftp, 'HELP'));
+var_dump(ftp_raw($ftp, 'HELP HELP'));
+
+var_dump(ftp_close($ftp));
+?>
+--EXPECT--
+bool(true)
+array(4) {
+ [0]=>
+ string(55) "214-There is help available for the following commands:"
+ [1]=>
+ string(5) " USER"
+ [2]=>
+ string(5) " HELP"
+ [3]=>
+ string(15) "214 end of list"
+}
+array(1) {
+ [0]=>
+ string(39) "214 Syntax: HELP [<SP> <string>] <CRLF>"
+}
+bool(true)
diff --git a/ext/ftp/tests/003.phpt b/ext/ftp/tests/003.phpt
new file mode 100644
index 000000000..db57ed56b
--- /dev/null
+++ b/ext/ftp/tests/003.phpt
@@ -0,0 +1,43 @@
+--TEST--
+FTP cwd
+--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'));
+
+var_dump(ftp_pwd($ftp));
+
+var_dump(ftp_chdir($ftp, 'mydir'));
+var_dump(ftp_pwd($ftp));
+
+var_dump(ftp_chdir($ftp, '/xpto/mydir'));
+var_dump(ftp_pwd($ftp));
+
+var_dump(ftp_cdup($ftp));
+var_dump(ftp_pwd($ftp));
+
+var_dump(ftp_chdir($ftp, '..'));
+var_dump(ftp_pwd($ftp));
+
+var_dump(ftp_close($ftp));
+?>
+--EXPECT--
+bool(true)
+string(1) "/"
+bool(true)
+string(6) "/mydir"
+bool(true)
+string(11) "/xpto/mydir"
+bool(true)
+string(5) "/xpto"
+bool(true)
+string(1) "/"
+bool(true)
diff --git a/ext/ftp/tests/004.phpt b/ext/ftp/tests/004.phpt
new file mode 100644
index 000000000..df6951b09
--- /dev/null
+++ b/ext/ftp/tests/004.phpt
@@ -0,0 +1,79 @@
+--TEST--
+FTP with bogus parameters
+--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'));
+
+var_dump(ftp_systype($ftp));
+
+/* some bogus usage */
+var_dump(ftp_alloc($ftp, array()));
+var_dump(ftp_cdup($ftp, 0));
+var_dump(ftp_chdir($ftp, array()));
+var_dump(ftp_chmod($ftp, 0666));
+var_dump(ftp_get($ftp, 1234,12));
+var_dump(ftp_close());
+var_dump(ftp_connect('sfjkfjaksfjkasjf'));
+var_dump(ftp_delete($ftp, array()));
+var_dump(ftp_exec($ftp, array()));
+
+var_dump(ftp_systype($ftp, 0));
+var_dump(ftp_pwd($ftp, array()));
+
+var_dump(ftp_login($ftp));
+var_dump(ftp_login($ftp, 'user', 'bogus'));
+
+var_dump(ftp_quit($ftp));
+?>
+--EXPECTF--
+bool(true)
+string(4) "UNIX"
+
+Warning: ftp_alloc() expects parameter 2 to be long, array given in %s004.php on line 12
+bool(false)
+
+Warning: ftp_cdup() expects exactly 1 parameter, 2 given in %s004.php on line 13
+NULL
+
+Warning: ftp_chdir() expects parameter 2 to be string, array given in %s004.php on line 14
+NULL
+
+Warning: ftp_chmod() expects exactly 3 parameters, 2 given in %s on line %d
+bool(false)
+
+Warning: ftp_get() expects at least 4 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ftp_close() expects exactly 1 parameter, 0 given in %s004.php on line 17
+NULL
+
+Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: %s in %s004.php on line 18
+bool(false)
+
+Warning: ftp_delete() expects parameter 2 to be string, array given in %s004.php on line 19
+NULL
+
+Warning: ftp_exec() expects parameter 2 to be string, array given in %s004.php on line 20
+NULL
+
+Warning: ftp_systype() expects exactly 1 parameter, 2 given in %s004.php on line 22
+NULL
+
+Warning: ftp_pwd() expects exactly 1 parameter, 2 given in %s004.php on line 23
+NULL
+
+Warning: ftp_login() expects exactly 3 parameters, 1 given in %s004.php on line 25
+NULL
+
+Warning: ftp_login(): Not logged in. in %s004.php on line 26
+bool(false)
+bool(true)
diff --git a/ext/ftp/tests/005.phpt b/ext/ftp/tests/005.phpt
new file mode 100644
index 000000000..bbc11e87a
--- /dev/null
+++ b/ext/ftp/tests/005.phpt
@@ -0,0 +1,86 @@
+--TEST--
+FTP with bogus server responses
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bogus = 1;
+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, 'anonymous', 'mail@example.com'));
+
+var_dump(ftp_alloc($ftp, 400));
+var_dump(ftp_cdup($ftp));
+var_dump(ftp_chdir($ftp, '~'));
+var_dump(ftp_chmod($ftp, 0666, 'x'));
+var_dump(ftp_delete($ftp, 'x'));
+var_dump(ftp_exec($ftp, 'x'));
+var_dump(ftp_fget($ftp, STDOUT, 'x', 0));
+var_dump(ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
+var_dump(ftp_get($ftp, 'x', 'y', 0));
+var_dump(ftp_mdtm($ftp, 'x'));
+var_dump(ftp_mkdir($ftp, 'x'));
+var_dump(ftp_nb_continue($ftp));
+var_dump(ftp_nb_fget($ftp, STDOUT, 'x', 0));
+var_dump(ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
+var_dump(ftp_systype($ftp));
+var_dump(ftp_pwd($ftp));
+var_dump(ftp_size($ftp, ''));
+var_dump(ftp_rmdir($ftp, ''));
+
+?>
+--EXPECTF--
+bool(true)
+bool(false)
+
+Warning: ftp_cdup(): Command not implemented (1). in %s005.php on line 11
+bool(false)
+
+Warning: ftp_chdir(): Command not implemented (2). in %s005.php on line 12
+bool(false)
+
+Warning: ftp_chmod(): Command not implemented (3). in %s005.php on line 13
+bool(false)
+
+Warning: ftp_delete(): Command not implemented (4). in %s005.php on line 14
+bool(false)
+
+Warning: ftp_exec(): Command not implemented (5). in %s005.php on line 15
+bool(false)
+
+Warning: ftp_fget(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 16
+bool(false)
+
+Warning: ftp_fput(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 17
+bool(false)
+
+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 (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(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 22
+bool(false)
+
+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 (8). in %s005.php on line 24
+bool(false)
+
+Warning: ftp_pwd(): Command not implemented (9). in %s005.php on line 25
+bool(false)
+int(-1)
+
+Warning: ftp_rmdir(): Command not implemented (11). in %s005.php on line 27
+bool(false)
diff --git a/ext/ftp/tests/006.phpt b/ext/ftp/tests/006.phpt
new file mode 100644
index 000000000..4d31be78c
--- /dev/null
+++ b/ext/ftp/tests/006.phpt
@@ -0,0 +1,100 @@
+--TEST--
+FTP with bogus parameters
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$ftp=null;
+
+var_dump(ftp_connect(array()));
+var_dump(ftp_connect('127.0.0.1', 0, -3));
+var_dump(ftp_raw($ftp));
+var_dump(ftp_mkdir($ftp));
+var_dump(ftp_rmdir($ftp));
+var_dump(ftp_nlist($ftp));
+var_dump(ftp_rawlist($ftp));
+var_dump(ftp_fget($ftp));
+var_dump(ftp_nb_fget($ftp));
+var_dump(ftp_nb_get($ftp));
+var_dump(ftp_pasv($ftp));
+var_dump(ftp_nb_continue());
+var_dump(ftp_fput());
+var_dump(ftp_nb_fput($ftp));
+var_dump(ftp_put($ftp));
+var_dump(ftp_nb_put($ftp));
+var_dump(ftp_size($ftp));
+var_dump(ftp_mdtm($ftp));
+var_dump(ftp_rename($ftp));
+var_dump(ftp_site($ftp));
+var_dump(ftp_set_option($ftp));
+var_dump(ftp_get_option($ftp));
+
+?>
+--EXPECTF--
+Warning: ftp_connect() expects parameter 1 to be string, array given in %s006.php on line 4
+NULL
+
+Warning: ftp_connect(): Timeout has to be greater than 0 in %s006.php on line 5
+bool(false)
+
+Warning: ftp_raw() expects exactly 2 parameters, 1 given in %s006.php on line 6
+NULL
+
+Warning: ftp_mkdir() expects exactly 2 parameters, 1 given in %s006.php on line 7
+NULL
+
+Warning: ftp_rmdir() expects exactly 2 parameters, 1 given in %s006.php on line 8
+NULL
+
+Warning: ftp_nlist() expects exactly 2 parameters, 1 given in %s006.php on line 9
+NULL
+
+Warning: ftp_rawlist() expects at least 2 parameters, 1 given in %s006.php on line 10
+NULL
+
+Warning: ftp_fget() expects at least 4 parameters, 1 given in %s006.php on line 11
+NULL
+
+Warning: ftp_nb_fget() expects at least 4 parameters, 1 given in %s006.php on line 12
+NULL
+
+Warning: ftp_nb_get() expects at least 4 parameters, 1 given in %s006.php on line 13
+NULL
+
+Warning: ftp_pasv() expects exactly 2 parameters, 1 given in %s006.php on line 14
+NULL
+
+Warning: ftp_nb_continue() expects exactly 1 parameter, 0 given in %s006.php on line 15
+NULL
+
+Warning: ftp_fput() expects at least 4 parameters, 0 given in %s006.php on line 16
+NULL
+
+Warning: ftp_nb_fput() expects at least 4 parameters, 1 given in %s006.php on line 17
+NULL
+
+Warning: ftp_put() expects at least 4 parameters, 1 given in %s006.php on line 18
+NULL
+
+Warning: ftp_nb_put() expects at least 4 parameters, 1 given in %s006.php on line 19
+NULL
+
+Warning: ftp_size() expects exactly 2 parameters, 1 given in %s006.php on line 20
+NULL
+
+Warning: ftp_mdtm() expects exactly 2 parameters, 1 given in %s006.php on line 21
+NULL
+
+Warning: ftp_rename() expects exactly 3 parameters, 1 given in %s006.php on line 22
+NULL
+
+Warning: ftp_site() expects exactly 2 parameters, 1 given in %s006.php on line 23
+NULL
+
+Warning: ftp_set_option() expects exactly 3 parameters, 1 given in %s006.php on line 24
+NULL
+
+Warning: ftp_get_option() expects exactly 2 parameters, 1 given in %s006.php on line 25
+NULL
diff --git a/ext/ftp/tests/bug27809.phpt b/ext/ftp/tests/bug27809.phpt
new file mode 100644
index 000000000..bcbe03f13
--- /dev/null
+++ b/ext/ftp/tests/bug27809.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #27809: ftp_systype returns null
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug27809=true;
+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, 'anonymous', 'IEUser@'));
+var_dump(ftp_systype($ftp));
+
+?>
+--EXPECT--
+bool(true)
+string(6) "OS/400"
diff --git a/ext/ftp/tests/bug37799.phpt b/ext/ftp/tests/bug37799.phpt
new file mode 100644
index 000000000..a47d58678
--- /dev/null
+++ b/ext/ftp/tests/bug37799.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #37799: ftp_ssl_connect() falls back to non-ssl connection
+--SKIPIF--
+<?php
+$ssl = 1;
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug37799=$ssl=1;
+require 'server.inc';
+
+$ftp = ftp_ssl_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+ftp_close($ftp);
+?>
+--EXPECTF--
+Warning: ftp_login(): bogus msg in %sbug37799.php on line 8
+bool(false)
diff --git a/ext/ftp/tests/bug39458-2.phpt b/ext/ftp/tests/bug39458-2.phpt
new file mode 100644
index 000000000..4cd2a4523
--- /dev/null
+++ b/ext/ftp/tests/bug39458-2.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories (other server behaviour)
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug39458=1;
+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'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--EXPECT--
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "file1"
+ [1]=>
+ string(5) "file1"
+ [2]=>
+ string(9) "file
+b0rk"
+}
+array(0) {
+}
+bool(false)
diff --git a/ext/ftp/tests/bug39458.phpt b/ext/ftp/tests/bug39458.phpt
new file mode 100644
index 000000000..5ea345776
--- /dev/null
+++ b/ext/ftp/tests/bug39458.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories
+--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'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--EXPECT--
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "file1"
+ [1]=>
+ string(5) "file1"
+ [2]=>
+ string(9) "file
+b0rk"
+}
+array(0) {
+}
+bool(false)
diff --git a/ext/ftp/tests/bug39583-2.phpt b/ext/ftp/tests/bug39583-2.phpt
new file mode 100644
index 000000000..44921b320
--- /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 000000000..3c73758dc
--- /dev/null
+++ b/ext/ftp/tests/bug39583.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #39583: FTP always transfers in binary mode
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug39583=1;
+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
new file mode 100644
index 000000000..62b6ec84b
--- /dev/null
+++ b/ext/ftp/tests/bug7216-2.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #7216: ftp_mkdir returns nothing (2)
+--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, 'anonymous', 'IEUser@'));
+// test for the correct behavior this time
+var_dump(ftp_mkdir($ftp, 'CVS'));
+
+?>
+--EXPECT--
+bool(true)
+string(20) "/path/to/ftproot/CVS"
diff --git a/ext/ftp/tests/bug7216.phpt b/ext/ftp/tests/bug7216.phpt
new file mode 100644
index 000000000..870e02ea6
--- /dev/null
+++ b/ext/ftp/tests/bug7216.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #7216: ftp_mkdir returns nothing
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug7216=true;
+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, 'anonymous', 'IEUser@'));
+var_dump(ftp_mkdir($ftp, 'CVS'));
+
+?>
+--EXPECT--
+bool(true)
+string(3) "CVS"
diff --git a/ext/ftp/tests/cert.pem b/ext/ftp/tests/cert.pem
new file mode 100644
index 000000000..94c61ffcc
--- /dev/null
+++ b/ext/ftp/tests/cert.pem
@@ -0,0 +1,48 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIIBmzCCAQQCAQAwWzELMAkGA1UEBhMCUFQxCzAJBgNVBAgTAkx4MQswCQYDVQQH
+EwJMeDEcMBoGA1UEChMTQSBtaW5oYSBlbXByZXNhLCBTQTEUMBIGA1UECxMLUEhQ
+IFFBIFRlYW0wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM9mfEOSYwXf58ch
+4NyO1QOU1XMfquz8OVpvMUITABLAevZpeQn6vZPHNyXHFQC0QC8scydK1rAYd2U+
+9K2aPub6ioMjYyjPpAE07l9EAAPUEBlqqsziB/wT8QjWkByyJEkYu+o0Wyjokhfn
+BMPvm52wLWUx9nvUeNDCftnKg1wxAgMBAAGgADANBgkqhkiG9w0BAQQFAAOBgQDD
+s1FeqPxnF2bWj8/dG8MyPaRfOAMVz1UsCZUciXIVG5LSIvR2qnMC3iEYt3s13sEq
+z8VJlNHa8nniE+VFNv093yIu+PlWXMEvb5y5EFqP2AYq3RAT+SJsSxGqIdzPZiKY
+INaktLCZmQ/E1v7/4hFzVRq9ydJI82DVS1nv282Whw==
+-----END CERTIFICATE REQUEST-----
+-----BEGIN CERTIFICATE-----
+MIIC4zCCAkygAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMQswCQYDVQQGEwJQVDEL
+MAkGA1UECBMCTHgxCzAJBgNVBAcTAkx4MRwwGgYDVQQKExNBIG1pbmhhIGVtcHJl
+c2EsIFNBMRQwEgYDVQQLEwtQSFAgUUEgVGVhbTAeFw0wNjExMTkxODIzNTNaFw0w
+NzExMTkxODIzNTNaMFsxCzAJBgNVBAYTAlBUMQswCQYDVQQIEwJMeDELMAkGA1UE
+BxMCTHgxHDAaBgNVBAoTE0EgbWluaGEgZW1wcmVzYSwgU0ExFDASBgNVBAsTC1BI
+UCBRQSBUZWFtMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPZnxDkmMF3+fH
+IeDcjtUDlNVzH6rs/DlabzFCEwASwHr2aXkJ+r2TxzclxxUAtEAvLHMnStawGHdl
+PvStmj7m+oqDI2Moz6QBNO5fRAAD1BAZaqrM4gf8E/EI1pAcsiRJGLvqNFso6JIX
+5wTD75udsC1lMfZ71HjQwn7ZyoNcMQIDAQABo4G2MIGzMB0GA1UdDgQWBBTIga5L
+q+Ub1SWXgNZRYCpq3c8Z+jCBgwYDVR0jBHwweoAUyIGuS6vlG9Ull4DWUWAqat3P
+GfqhX6RdMFsxCzAJBgNVBAYTAlBUMQswCQYDVQQIEwJMeDELMAkGA1UEBxMCTHgx
+HDAaBgNVBAoTE0EgbWluaGEgZW1wcmVzYSwgU0ExFDASBgNVBAsTC1BIUCBRQSBU
+ZWFtggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAe6AA8aC3KDI8
+smd+7XWjaTSp1Q0uMkEZ2PEBzif2I1aPPqw1CQykJ1iDdC/8PJ1yEIezloP2XQoZ
+NjTaCO+uubay03ncoPTZvDUwExN9BYFAYgc2z3tLMHYbA7kM2sIbKys7ZQegLibr
+TSKYQOBeYA/FB9GHECJGU3zBRvYi+Og=
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: DES-EDE3-CBC,928762DB6DE222AD
+
+oOxNUBX0wrqmRqb3IEZMogc1bnVm6JoW6YFjGfHNcIz0jS7UPDhUFDR26y0dYujL
+LEgxOcYo8ItvGcXSRbs+3W7lISbosgkB0DOaKx5jVmOGwUVRergUUSY8rbf93FtP
+27CEvAfsU6do5HmlJ34mYZW1k+onCznlJXJkupQ5jmiily3GwEdr/5mMIVOmXQ6p
+xWkxHySDKyVbR0v4JY3SJLRBuhgofYNG5155PiqZ7KwYY4Aw60eVgINsvJCF9/8b
+kEj+lecHbBdAf7N82320Ga+F+VeFnUl0gWFjoIF9UFCO80+7ZvIGdGlyPkr4zMvt
+TsC1snJQdHg+IlT3sGayYrQANpTG6GPYhn3KEvK5aqq+bPEe5lija0gw34jbPCo+
+TjHR76lToxzubGZODyyF/rjl5KwUbqTCNuv1PX1jTx7n7sCbu+KHpqXMhTHLKtby
++Wh7WAfsVrbIW+P85/mkfhPbPZ2621f9cyStdFGgWU4dHdD00HIGOgAJvUSbC2Au
+oVUoKf2818t1s9aA4ptog04sNi+Ixu+z+3yYNLZj51j4ZX3KuXxLIiQvlvFQ8LQi
+RHGQk3u2W3iNtDKKUQjMPaB2FlVtC7FmtHBCpRmos6ld240DDyucqMdIDTMaqV0+
+sL4X+LIeBM/hP/IquRTuQBHBmgjkN4845ihTUJOanyKx605ANq/roHzXrbIxhR5p
+pcJLCBMLMWgdOCJMZRavSq04iXeNfP6Mk/joVpHS62Ljdfc94BBLfsOKOErA20Nq
+lfvbZqy2tI5IIDoq05S8FU0DYNqq/hyrv9Udo8IAo+WkBOABm0x/WA==
+-----END RSA PRIVATE KEY-----
+ \ No newline at end of file
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc
new file mode 100644
index 000000000..c101c7c70
--- /dev/null
+++ b/ext/ftp/tests/server.inc
@@ -0,0 +1,258 @@
+<?php
+
+$socket = null;
+$errno = 0;
+$context = stream_context_create(array('ssl' => array('local_cert' => dirname(__FILE__).'/cert.pem', 'passphrase' => 'pass')));
+
+for ($i=0; $i<10 && !$socket; ++$i) {
+ $port = rand(50000, 65535);
+ $socket = stream_socket_server("tcp://127.0.0.1:$port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
+}
+
+if (!$socket) {
+ die("could not start/bind the ftp server\n");
+}
+
+$pid = pcntl_fork();
+
+if ($pid) {
+
+function dump_and_exit($buf)
+{
+ var_dump($buf);
+ fclose($GLOBALS['s']);
+ exit;
+}
+
+function anonymous()
+{
+ return $GLOBALS['user'] === 'anonymous';
+}
+
+/* quick&dirty realpath() like function */
+function change_dir($dir)
+{
+ global $cwd;
+
+ if ($dir[0] == '/') {
+ $cwd = $dir;
+ return;
+ }
+
+ $cwd = "$cwd/$dir";
+
+ do {
+ $old = $cwd;
+ $cwd = preg_replace('@/?[^/]+/\.\.@', '', $cwd);
+ } while ($old != $cwd);
+
+ $cwd = strtr($cwd, array('//' => '/'));
+ if (!$cwd) $cwd = '/';
+}
+
+
+$s = stream_socket_accept($socket);
+if (!$s) die("Error accepting a new connection\n");
+
+fputs($s, "220----- PHP FTP server 0.3 -----\r\n220 Service ready\r\n");
+$buf = fread($s, 2048);
+
+
+function user_auth($buf) {
+ global $user, $s, $ssl, $bug37799;
+
+if (!empty($ssl)) {
+ if ($buf !== "AUTH TLS\r\n") {
+ fputs($s, "500 Syntax error, command unrecognized.\r\n");
+ dump_and_exit($buf);
+ }
+
+ if (empty($bug37799)) {
+ fputs($s, "234 auth type accepted\r\n");
+ } else {
+ fputs($s, "666 dummy\r\n");
+ fputs($s, "666 bogus msg\r\n");
+ exit;
+ }
+
+ if (!stream_socket_enable_crypto($s, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER)) {
+ die("SSLv23 handshake failed.\n");
+ }
+
+ if (!preg_match('/^PBSZ \d+\r\n$/', $buf = fread($s, 2048))) {
+ fputs($s, "501 bogus data\r\n");
+ dump_and_exit($buf);
+ }
+
+ fputs($s, "200 OK\r\n");
+ $buf = fread($s, 2048);
+
+ if ($buf !== "PROT P\r\n") {
+ fputs($s, "504 Wrong protection.\r\n");
+ dump_and_exit($buf);
+ }
+
+ fputs($s, "200 OK\r\n");
+
+ $buf = fread($s, 2048);
+}
+
+if (!preg_match('/^USER (\w+)\r\n$/', $buf, $m)) {
+ fputs($s, "500 Syntax error, command unrecognized.\r\n");
+ dump_and_exit($buf);
+}
+$user = $m[1];
+if ($user !== 'user' && $user !== 'anonymous') {
+ fputs($s, "530 Not logged in.\r\n");
+ fclose($s);
+ exit;
+}
+
+if (anonymous()) {
+ fputs($s, "230 Anonymous user logged in\r\n");
+
+} else {
+ fputs($s, "331 User name ok, need password\r\n");
+
+ if (!preg_match('/^PASS (\w+)\r\n$/', $buf = fread($s, 100), $m)) {
+ fputs($s, "500 Syntax error, command unrecognized.\r\n");
+ dump_and_exit($buf);
+ }
+
+ $pass = $m[1];
+ if ($pass === 'pass') {
+ fputs($s, "230 User logged in\r\n");
+ } else {
+ fputs($s, "530 Not logged in.\r\n");
+ fclose($s);
+ exit;
+ }
+}
+}
+
+user_auth($buf);
+
+$cwd = '/';
+$num_bogus_cmds = 0;
+
+while($buf = fread($s, 4098)) {
+
+ if (!empty($bogus)) {
+ fputs($s, "502 Command not implemented (".$num_bogus_cmds++.").\r\n");
+
+ } else if ($buf === "HELP\r\n") {
+ fputs($s, "214-There is help available for the following commands:\r\n");
+ fputs($s, " USER\r\n");
+ fputs($s, " HELP\r\n");
+ fputs($s, "214 end of list\r\n");
+
+ } elseif ($buf === "HELP HELP\r\n") {
+ fputs($s, "214 Syntax: HELP [<SP> <string>] <CRLF>\r\n");
+
+ } elseif ($buf === "PWD\r\n") {
+ fputs($s, "257 \"$cwd\" is current directory.\r\n");
+
+ } elseif ($buf === "CDUP\r\n") {
+ change_dir('..');
+ fputs($s, "250 CDUP command successful.\r\n");
+
+ } elseif ($buf === "SYST\r\n") {
+ if (isset($bug27809)) {
+ fputs($s, "215 OS/400 is the remote operating system. The TCP/IP version is \"V5R2M0\"\r\n");
+ } else {
+ 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) || isset($bug39583)) && $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");
+
+ } elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) {
+
+ if (isset($m[1]) && $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;
+ }
+
+ 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;
+ }
+
+ if (empty($m[1]) || $m[1] !== 'emptydir') {
+ fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n");
+ }
+
+ fputs($s, "226 Closing data Connection.\r\n");
+ fclose($fs);
+
+ } elseif (preg_match("~^MKD ([A-Za-z./]+)\r\n$~", $buf, $m)) {
+ if (isset($bug7216)) {
+ fputs($s, "257 OK.\r\n");
+ } else {
+ fputs($s, "257 \"/path/to/ftproot$cwd$m[1]\" created.\r\n");
+ }
+
+ } elseif (preg_match('/^USER /', $buf)) {
+ user_auth($buf);
+
+ } else {
+ fputs($s, "500 Syntax error, command unrecognized.\r\n");
+ dump_and_exit($buf);
+ }
+}
+
+fclose($s);
+exit;
+}
+
+fclose($socket);
+?>
diff --git a/ext/ftp/tests/skipif.inc b/ext/ftp/tests/skipif.inc
new file mode 100644
index 000000000..9ab6ad985
--- /dev/null
+++ b/ext/ftp/tests/skipif.inc
@@ -0,0 +1,5 @@
+<?php
+if (!extension_loaded('ftp')) die('skip ftp extension not loaded');
+if (!function_exists('pcntl_fork')) die('skip fork not available');
+if (!empty($ssl) && !extension_loaded('openssl')) die('skip openssl extension not loaded');
+?>