summaryrefslogtreecommitdiff
path: root/ext/ftp/php_ftp.c
diff options
context:
space:
mode:
authorAndreas Treichel <gmblar+github@gmail.com>2017-01-28 04:20:40 +0100
committerJoe Watkins <krakjoe@php.net>2017-01-29 07:28:22 +0000
commit0103d1e3bc7b3861a2bff81de204eceb3f4c212a (patch)
tree943bce4f797f3643824cbf6dda05edf7da524b11 /ext/ftp/php_ftp.c
parent3de7b2ab523947de3cf85e230a242b1af884641a (diff)
downloadphp-git-0103d1e3bc7b3861a2bff81de204eceb3f4c212a.tar.gz
FTP: implement MLSD for structured listing of directories, decribed at https://tools.ietf.org/html/rfc3659
Diffstat (limited to 'ext/ftp/php_ftp.c')
-rw-r--r--ext/ftp/php_ftp.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index 631eb69744..dc7351ff82 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -117,6 +117,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_rawlist, 0, 0, 2)
ZEND_ARG_INFO(0, recursive)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_ftp_mlsd, 0)
+ ZEND_ARG_INFO(0, ftp)
+ ZEND_ARG_INFO(0, directory)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_ftp_systype, 0)
ZEND_ARG_INFO(0, ftp)
ZEND_END_ARG_INFO()
@@ -254,6 +259,7 @@ const zend_function_entry php_ftp_functions[] = {
PHP_FE(ftp_alloc, arginfo_ftp_alloc)
PHP_FE(ftp_nlist, arginfo_ftp_nlist)
PHP_FE(ftp_rawlist, arginfo_ftp_rawlist)
+ PHP_FE(ftp_mlsd, arginfo_ftp_mlsd)
PHP_FE(ftp_systype, arginfo_ftp_systype)
PHP_FE(ftp_pasv, arginfo_ftp_pasv)
PHP_FE(ftp_get, arginfo_ftp_get)
@@ -748,6 +754,36 @@ PHP_FUNCTION(ftp_rawlist)
}
/* }}} */
+/* {{{ proto array ftp_mlsd(resource stream, string directory)
+ Returns a detailed listing of a directory as an array of output lines */
+PHP_FUNCTION(ftp_mlsd)
+{
+ zval *z_ftp;
+ ftpbuf_t *ftp;
+ char **llist, **ptr, *dir;
+ size_t dir_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
+ return;
+ }
+
+ if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ /* get raw directory listing */
+ if (NULL == (llist = ftp_mlsd(ftp, dir, dir_len))) {
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ for (ptr = llist; *ptr; ptr++) {
+ add_next_index_string(return_value, *ptr);
+ }
+ efree(llist);
+}
+/* }}} */
+
/* {{{ proto string ftp_systype(resource stream)
Returns the system type identifier */
PHP_FUNCTION(ftp_systype)