From 0103d1e3bc7b3861a2bff81de204eceb3f4c212a Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Sat, 28 Jan 2017 04:20:40 +0100 Subject: FTP: implement MLSD for structured listing of directories, decribed at https://tools.ietf.org/html/rfc3659 --- ext/ftp/php_ftp.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'ext/ftp/php_ftp.c') 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) -- cgit v1.2.1