summaryrefslogtreecommitdiff
path: root/ext/ftp/tests
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/ftp/tests
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
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/ftp_alloc_basic1.phpt21
-rw-r--r--ext/ftp/tests/ftp_alloc_basic2.phpt23
-rw-r--r--ext/ftp/tests/ftp_chmod_basic.phpt21
-rw-r--r--ext/ftp/tests/ftp_exec_basic.phpt21
-rw-r--r--ext/ftp/tests/ftp_fget_basic.phpt43
-rw-r--r--ext/ftp/tests/ftp_fget_basic1.phpt32
-rw-r--r--ext/ftp/tests/ftp_fget_basic2.phpt32
-rw-r--r--ext/ftp/tests/ftp_fget_basic3.phpt32
-rw-r--r--ext/ftp/tests/ftp_get_basic.phpt40
-rw-r--r--ext/ftp/tests/ftp_mdtm_basic.phpt48
-rw-r--r--ext/ftp/tests/ftp_nb_fget_basic1.phpt32
-rw-r--r--ext/ftp/tests/ftp_nb_fget_basic2.phpt32
-rw-r--r--ext/ftp/tests/ftp_nb_fget_basic3.phpt32
-rw-r--r--ext/ftp/tests/ftp_rawlist_basic2.phpt21
-rw-r--r--ext/ftp/tests/ftp_rmdir_basic.phpt21
-rw-r--r--ext/ftp/tests/server.inc410
-rw-r--r--ext/ftp/tests/skipif.inc5
32 files changed, 1521 insertions, 0 deletions
diff --git a/ext/ftp/tests/001.phpt b/ext/ftp/tests/001.phpt
new file mode 100644
index 0000000..38475d3
--- /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 0000000..e27113f
--- /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 0000000..db57ed5
--- /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 0000000..df6951b
--- /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 0000000..bbc11e8
--- /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 0000000..4d31be7
--- /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 0000000..ff9765c
--- /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 0000000..bc9ce00
--- /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 0000000..9e4be5d
--- /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 0000000..8286649
--- /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 0000000..0a8423d
--- /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 0000000..b3af56e
--- /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 0000000..23ab851
--- /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 0000000..000bb1d
--- /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 0000000..94c61ff
--- /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/ftp_alloc_basic1.phpt b/ext/ftp/tests/ftp_alloc_basic1.phpt
new file mode 100644
index 0000000..b2bdf74
--- /dev/null
+++ b/ext/ftp/tests/ftp_alloc_basic1.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_alloc returns true
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--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");
+ftp_login($ftp, 'user', 'pass');
+
+var_dump(ftp_alloc($ftp, 1024));
+?>
+--EXPECT--
+bool(true) \ No newline at end of file
diff --git a/ext/ftp/tests/ftp_alloc_basic2.phpt b/ext/ftp/tests/ftp_alloc_basic2.phpt
new file mode 100644
index 0000000..b9e4253
--- /dev/null
+++ b/ext/ftp/tests/ftp_alloc_basic2.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Testing ftp_alloc returns true
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--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");
+ftp_login($ftp, 'user', 'pass');
+
+var_dump(ftp_alloc($ftp, 1024, $result));
+var_dump($result);
+?>
+--EXPECT--
+bool(true)
+string(20) "1024 bytes allocated" \ No newline at end of file
diff --git a/ext/ftp/tests/ftp_chmod_basic.phpt b/ext/ftp/tests/ftp_chmod_basic.phpt
new file mode 100644
index 0000000..baaa25a
--- /dev/null
+++ b/ext/ftp/tests/ftp_chmod_basic.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_chmod returns file mode
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--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");
+ftp_login($ftp, 'user', 'pass');
+
+var_dump(ftp_chmod($ftp, 0644, 'test.txt'));
+?>
+--EXPECT--
+int(420)
diff --git a/ext/ftp/tests/ftp_exec_basic.phpt b/ext/ftp/tests/ftp_exec_basic.phpt
new file mode 100644
index 0000000..4a1f63e
--- /dev/null
+++ b/ext/ftp/tests/ftp_exec_basic.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_exec returns true
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_exec($ftp, 'ls -al'));
+?>
+--EXPECT--
+bool(true) \ No newline at end of file
diff --git a/ext/ftp/tests/ftp_fget_basic.phpt b/ext/ftp/tests/ftp_fget_basic.phpt
new file mode 100644
index 0000000..d736f8c
--- /dev/null
+++ b/ext/ftp/tests/ftp_fget_basic.phpt
@@ -0,0 +1,43 @@
+--TEST--
+FTP ftp_fget file for both binary and ASCII transfer modes
+--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
+$fp = tmpfile();
+var_dump(ftp_fget($ftp, $fp ,'a story.txt', FTP_ASCII));
+fseek($fp, 0);
+echo fgets($fp);
+
+$postition = ftell($fp);
+//test binary data transfer
+var_dump(ftp_fget($ftp, $fp, 'binary data.bin', FTP_BINARY));
+fseek($fp, $postition);
+var_dump(urlencode(fgets($fp)));
+
+//test non-existant file request
+ftp_fget($ftp, $fp ,'a warning.txt', FTP_ASCII);
+
+//remove file
+fclose($fp);
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+For sale: baby shoes, never worn.
+bool(true)
+string(21) "BINARYFoo%00Bar%0D%0A"
+
+Warning: ftp_fget(): a warning: No such file or directory in %sftp_fget_basic.php on line %d
diff --git a/ext/ftp/tests/ftp_fget_basic1.phpt b/ext/ftp/tests/ftp_fget_basic1.phpt
new file mode 100644
index 0000000..475f718
--- /dev/null
+++ b/ext/ftp/tests/ftp_fget_basic1.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_fget ignore autoresume if autoseek is switched off
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+ftp_set_option($ftp, FTP_AUTOSEEK, false);
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+$handle = fopen($local_file, 'w');
+
+var_dump(ftp_fget($ftp, $handle, 'fget.txt', FTP_ASCII, FTP_AUTORESUME));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+bool(true)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_fget_basic2.phpt b/ext/ftp/tests/ftp_fget_basic2.phpt
new file mode 100644
index 0000000..00a2675
--- /dev/null
+++ b/ext/ftp/tests/ftp_fget_basic2.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_fget autoresume
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+file_put_contents($local_file, 'ASCIIFoo');
+$handle = fopen($local_file, 'a');
+
+var_dump(ftp_fget($ftp, $handle, 'fgetresume.txt', FTP_ASCII, FTP_AUTORESUME));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+bool(true)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_fget_basic3.phpt b/ext/ftp/tests/ftp_fget_basic3.phpt
new file mode 100644
index 0000000..b709870
--- /dev/null
+++ b/ext/ftp/tests/ftp_fget_basic3.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_fget resume parameter
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+file_put_contents($local_file, 'ASCIIFoo');
+$handle = fopen($local_file, 'a');
+
+var_dump(ftp_fget($ftp, $handle, 'fgetresume.txt', FTP_ASCII, 8));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+bool(true)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_get_basic.phpt b/ext/ftp/tests/ftp_get_basic.phpt
new file mode 100644
index 0000000..23fd8d0
--- /dev/null
+++ b/ext/ftp/tests/ftp_get_basic.phpt
@@ -0,0 +1,40 @@
+--TEST--
+FTP ftp_get file for both binary and ASCII transfer modes
+--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(dirname(__FILE__), "ftp_test");
+var_dump(ftp_get($ftp, $tmpfname ,'a story.txt', FTP_ASCII));
+echo file_get_contents($tmpfname);
+unlink($tmpfname);
+
+//test binary data transfer
+$tmpfname = tempnam(dirname(__FILE__), "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
diff --git a/ext/ftp/tests/ftp_mdtm_basic.phpt b/ext/ftp/tests/ftp_mdtm_basic.phpt
new file mode 100644
index 0000000..39aeb76
--- /dev/null
+++ b/ext/ftp/tests/ftp_mdtm_basic.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test the File Modification Time as described in http://tools.ietf.org/html/rfc3659#section-3.1
+--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'));
+
+
+date_default_timezone_set('UTC');
+
+$time = ftp_mdtm($ftp, "A");
+echo date("F d Y H:i:s u",$time), PHP_EOL;
+
+$time = ftp_mdtm($ftp, "B");
+echo date("F d Y H:i:s u",$time), PHP_EOL;
+
+$time = ftp_mdtm($ftp, "C");
+echo date("F d Y H:i:s u",$time), PHP_EOL;
+
+$time = ftp_mdtm($ftp, "D");
+var_dump($time);
+
+$time = ftp_mdtm($ftp, "19990929043300 File6");
+echo date("F d Y H:i:s u",$time), PHP_EOL;
+
+$time = ftp_mdtm($ftp, "MdTm 19990929043300 file6");
+var_dump($time);
+
+?>
+--EXPECTF--
+bool(true)
+June 15 1998 10:00:45 000000
+June 15 1998 10:00:45 000000
+July 05 1998 13:23:16 000000
+int(-1)
+October 05 1999 21:31:02 000000
+int(-1)
diff --git a/ext/ftp/tests/ftp_nb_fget_basic1.phpt b/ext/ftp/tests/ftp_nb_fget_basic1.phpt
new file mode 100644
index 0000000..cac4eec
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_fget_basic1.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_nb_fget ignore autoresume if autoseek is switched off
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+ftp_set_option($ftp, FTP_AUTOSEEK, false);
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+$handle = fopen($local_file, 'w');
+
+var_dump(ftp_nb_fget($ftp, $handle, 'fget.txt', FTP_ASCII, FTP_AUTORESUME));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+int(2)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_nb_fget_basic2.phpt b/ext/ftp/tests/ftp_nb_fget_basic2.phpt
new file mode 100644
index 0000000..dc92f4e
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_fget_basic2.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_nb_fget autoresume
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+file_put_contents($local_file, 'ASCIIFoo');
+$handle = fopen($local_file, 'a');
+
+var_dump(ftp_nb_fget($ftp, $handle, 'fgetresume.txt', FTP_ASCII, FTP_AUTORESUME));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+int(2)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_nb_fget_basic3.phpt b/ext/ftp/tests/ftp_nb_fget_basic3.phpt
new file mode 100644
index 0000000..d1a87c4
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_fget_basic3.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing ftp_nb_fget resume parameter
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt";
+file_put_contents($local_file, 'ASCIIFoo');
+$handle = fopen($local_file, 'a');
+
+var_dump(ftp_nb_fget($ftp, $handle, 'fgetresume.txt', FTP_ASCII, 8));
+var_dump(file_get_contents($local_file));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "localfile.txt");
+?>
+--EXPECT--
+int(2)
+string(12) "ASCIIFooBar
+"
diff --git a/ext/ftp/tests/ftp_rawlist_basic2.phpt b/ext/ftp/tests/ftp_rawlist_basic2.phpt
new file mode 100644
index 0000000..1d93643
--- /dev/null
+++ b/ext/ftp/tests/ftp_rawlist_basic2.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_rawlist returns false on server error
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_rawlist($ftp, 'no_exists/'));
+?>
+--EXPECT--
+bool(false) \ No newline at end of file
diff --git a/ext/ftp/tests/ftp_rmdir_basic.phpt b/ext/ftp/tests/ftp_rmdir_basic.phpt
new file mode 100644
index 0000000..6626cb4
--- /dev/null
+++ b/ext/ftp/tests/ftp_rmdir_basic.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_rmdir returns true
+--CREDITS--
+Rodrigo Moyle <eu [at] rodrigorm [dot] com [dot] br>
+#testfest PHPSP on 2009-06-20
+--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");
+ftp_login($ftp, 'user', 'pass');
+
+var_dump(ftp_rmdir($ftp, 'www/'));
+?>
+--EXPECT--
+bool(true) \ 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 0000000..8617880
--- /dev/null
+++ b/ext/ftp/tests/server.inc
@@ -0,0 +1,410 @@
+<?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);
+}
+//set anther random port that is not the same as $port
+do{
+ $pasv_port = rand(50000, 65535);
+}while($pasv_port == $port);
+
+if (!$socket) {
+ die("could not start/bind the ftp server\n");
+}
+
+
+
+
+$pid = pcntl_fork();
+
+
+
+function pasv_listen($action){
+ global $pasv_port, $tmp_file;
+ $tmp_file = 'nm2.php';
+ $pid = pcntl_fork();
+ if($pid === 0){
+ $soc = stream_socket_server("tcp://127.0.0.1:$pasv_port");
+ $fs = stream_socket_accept($soc, 3);
+ switch ($action) {
+ case 'fget':
+ case 'get':
+ //listen for 3 seconds 3 seconds
+ fputs($fs, "I am passive.\r\n");
+ break;
+ case 'put':
+ file_put_contents($tmp_file, stream_get_contents($fs));
+ break;
+ case 'list':
+ fputs($fs, "drwxr-x--- 3 owner group 4096 Jul 12 12:16 .\r\n");
+ fputs($fs, "drwxr-x--- 3 owner group 4096 Jul 12 12:16 ..\r\n");
+ fputs($fs, "drwxr-x--- 3 owner group 4096 Jul 12 12:16 public_ftp\r\n");
+ break;
+ case 'list_null':
+ fputs($fs, "\r\n");
+ break;
+ }
+ fclose($fs);
+ exit;
+ }
+}
+
+
+
+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(empty($pasv))
+ {
+ 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);
+ }else{
+ $data = file_get_contents('nm2.php');
+ $orig = file_get_contents(dirname(__FILE__).'/'.$m[1]);
+ if ( $orig === $data) {
+ fputs($s, "226 Closing data Connection.\r\n");
+
+ } else {
+ var_dump($data);
+ var_dump($orig);
+ fputs($s, "552 Requested file action aborted.\r\n");
+ }
+ }
+
+ } 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);
+
+ } elseif (preg_match('/^MDTM ([\w\h]+)/', $buf, $matches)) {
+ switch ($matches [1]){
+ case "A":
+ fputs($s, "213 19980615100045.014\r\n");
+ break;
+ case "B":
+ fputs($s, "213 19980615100045.014\r\n");
+ break;
+ case "C":
+ fputs($s, "213 19980705132316\r\n");
+ break;
+ case "19990929043300 File6":
+ fputs($s, "213 19991005213102\r\n");
+ break;
+ default :
+ fputs($s, "550 No file named \"{$matches [1]}\"\r\n");
+ break;
+ }
+ }elseif (preg_match('/^RETR ([\w\h]+)/', $buf, $matches)) {
+ if(!empty($pasv)){
+ ;
+ }
+ else if (!$fs = stream_socket_client("tcp://$host:$port")) {
+ fputs($s, "425 Can't open data connection\r\n");
+ continue;
+ }
+
+ switch($matches[1]){
+
+ case "pasv":
+ fputs($s, "150 File status okay; about to open data connection.\r\n");
+ //the data connection is handled in another forked process
+ // called from outside this while loop
+ fputs($s, "226 Closing data Connection.\r\n");
+ break;
+ 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;
+ case "fget":
+ fputs($s, "150 File status okay; about to open data connection.\r\n");
+ $transfer_type = $ascii? 'ASCII' : 'BINARY' ;
+ fputs($fs, $transfer_type."FooBar\r\n");
+ fputs($s, "226 Closing data Connection.\r\n");
+ break;
+ case "fgetresume":
+ fputs($s, "150 File status okay; about to open data connection.\r\n");
+ $transfer_type = $ascii? 'ASCII' : 'BINARY' ;
+ fputs($fs, "Bar\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;
+ }
+ if(isset($fs))
+ fclose($fs);
+
+
+ }elseif (preg_match('/^PASV/', $buf, $matches)) {
+ $port = $pasv_port;
+ $p2 = $port % ((int) 1 << 8);
+ $p1 = ($port-$p2)/((int) 1 << 8);
+ $host = "127.0.0.1";
+ fputs($s, "227 Entering Passive Mode. (127,0,0,1,{$p1},{$p2})\r\n");
+
+
+ } elseif (preg_match('/^SITE EXEC/', $buf, $matches)) {
+ fputs($s, "200 OK\r\n");
+
+ } elseif (preg_match('/^RMD/', $buf, $matches)) {
+ fputs($s, "250 OK\r\n");
+
+ } elseif (preg_match('/^SITE CHMOD/', $buf, $matches)) {
+ fputs($s, "200 OK\r\n");
+
+ } elseif (preg_match('/^ALLO (\d+)/', $buf, $matches)) {
+ fputs($s, "200 " . $matches[1] . " bytes allocated\r\n");
+
+ }elseif (preg_match('/^LIST www\//', $buf, $matches)) {
+ fputs($s, "150 Opening ASCII mode data connection for file list\r\n");
+ fputs($s, "226 Transfer complete\r\n");
+
+ }elseif (preg_match('/^LIST no_exists\//', $buf, $matches)) {
+ fputs($s, "425 Error establishing connection\r\n");
+
+ }elseif (preg_match('/^REST \d+/', $buf, $matches)) {
+ fputs($s, "350 OK\r\n");
+ }
+
+ else {
+ fputs($s, "500 Syntax error, command unrecognized.\r\n");
+ dump_and_exit($buf);
+ }
+ }
+ fclose($s);
+ exit;
+}
+
+fclose($socket);
+?> \ No newline at end of file
diff --git a/ext/ftp/tests/skipif.inc b/ext/ftp/tests/skipif.inc
new file mode 100644
index 0000000..9ab6ad9
--- /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');
+?>