From: Sara Golemon Date: Fri, 31 Jan 2003 04:54:57 +0000 (+0000) Subject: Add ftp_raw() to send raw command strings to an FTP server. X-Git-Tag: RELEASE_0_5~1351 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81797baed4386e726b79aaa99f7fb4887d8d9348;p=php Add ftp_raw() to send raw command strings to an FTP server. --- diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 0180c4f598..8cafa790e0 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -443,6 +443,27 @@ ftp_exec(ftpbuf_t *ftp, const char *cmd) } /* }}} */ +/* {{{ ftp_raw + */ +void +ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) +{ + if (ftp == NULL || cmd == NULL) { + RETURN_NULL(); + } + if (!ftp_putcmd(ftp, cmd, NULL)) { + RETURN_NULL(); + } + array_init(return_value); + while (ftp_readline(ftp)) { + add_next_index_string(return_value, ftp->inbuf, 1); + if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') { + return; + } + } +} +/* }}} */ + /* {{{ ftp_chdir */ int diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index 19233a5d6c..2fffe08f94 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -121,6 +121,9 @@ const char* ftp_pwd(ftpbuf_t *ftp); /* exec a command [special features], return true on success, false on error */ int ftp_exec(ftpbuf_t *ftp, const char *cmd); +/* send a raw ftp command, return response as a hashtable, NULL on error */ +void ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value); + /* changes directories, return true on success, false on error */ int ftp_chdir(ftpbuf_t *ftp, const char *dir); diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index d43211ad39..2cc8d198ab 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -56,6 +56,7 @@ function_entry php_ftp_functions[] = { PHP_FE(ftp_cdup, NULL) PHP_FE(ftp_chdir, NULL) PHP_FE(ftp_exec, NULL) + PHP_FE(ftp_raw, NULL) PHP_FE(ftp_mkdir, NULL) PHP_FE(ftp_rmdir, NULL) PHP_FE(ftp_chmod, NULL) @@ -331,6 +332,26 @@ PHP_FUNCTION(ftp_exec) } /* }}} */ +/* {{{ proto array ftp_raw(resource stream, string command) + Sends a literal command to the FTP server */ +PHP_FUNCTION(ftp_raw) +{ + zval *z_ftp; + ftpbuf_t *ftp; + char *cmd; + int cmd_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf); + + /* execute arbitrary ftp command */ + ftp_raw(ftp, cmd, return_value); +} +/* }}} */ + /* {{{ proto string ftp_mkdir(resource stream, string directory) Creates a directory and returns the absolute path for the new directory or false on error */ PHP_FUNCTION(ftp_mkdir) diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h index f203987b23..47e5ba1b34 100644 --- a/ext/ftp/php_ftp.h +++ b/ext/ftp/php_ftp.h @@ -43,6 +43,7 @@ PHP_FUNCTION(ftp_pwd); PHP_FUNCTION(ftp_cdup); PHP_FUNCTION(ftp_chdir); PHP_FUNCTION(ftp_exec); +PHP_FUNCTION(ftp_raw); PHP_FUNCTION(ftp_mkdir); PHP_FUNCTION(ftp_rmdir); PHP_FUNCTION(ftp_chmod);