note 3798 deleted from FTP functions by sniper

From: Date: Wed, 24 Jan 2001 08:50:21 +0000
Subject: note 3798 deleted from FTP functions by sniper
Groups: php.notes 
Request: Send a blank email to php-notes+get-10207@lists.php.net to get a copy of this message
here is a patch to add a ftp_exec command to php_ftp part <pre> int ftp_exec(int ftp_stream, string cmd); </pre> it send the cmd to the SITE EXEC layer of the ftpd when this solution is available. <br> <br> Here is the patch : in php source directory, type <pre> cd functions patch &lt; ftp_exec.patch <br> <br> <pre> diff -u -r functions/ftp.c.orig functions/ftp.c --- functions/ftp.c.orig Sun Jan 9 12:06:00 2000 +++ functions/ftp.c Wed Feb 16 09:47:03 2000 @@ -305,6 +305,20 @@ return ftp->pwd; } +int +ftp_exec(ftpbuf_t *ftp, const char *cmd) +{ + if (ftp == NULL) + return 0; + + if (!ftp_putcmd(ftp, "SITE EXEC", cmd)) + return 0; + if (!ftp_getresp(ftp) || ftp->resp != 200) + return 0; + + return 1; +} + int ftp_chdir(ftpbuf_t *ftp, const char *dir) diff -u -r functions/ftp.h.orig functions/ftp.h --- functions/ftp.h.orig Sun Jan 9 12:06:00 2000 +++ functions/ftp.h Wed Feb 16 09:48:50 2000 @@ -108,6 +108,9 @@ /* changes directories, return true on success, false on error */ int ftp_chdir(ftpbuf_t *ftp, const char *dir); +/* exec a command [special features], return true on success, false on error */ +int ftp_exec(ftpbuf_t *ftp, const char *cmd); + /* changes to parent directory, return true on success, false on error */ int ftp_cdup(ftpbuf_t *ftp); diff -u -r functions/php_ftp.c.orig functions/php_ftp.c --- functions/php_ftp.c.orig Sun Jan 9 12:06:00 2000 +++ functions/php_ftp.c Wed Feb 16 09:51:01 2000 @@ -52,6 +52,7 @@ PHP_FE(ftp_pwd, NULL) PHP_FE(ftp_cdup, NULL) PHP_FE(ftp_chdir, NULL) + PHP_FE(ftp_exec, NULL) PHP_FE(ftp_mkdir, NULL) PHP_FE(ftp_rmdir, NULL) PHP_FE(ftp_nlist, NULL) @@ -292,6 +293,36 @@ /* change directories */ if (!ftp_chdir(ftp, arg2->value.str.val)) { php_error(E_WARNING, "ftp_chdir: %s", ftp->inbuf); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int ftp_exec(int stream, string command) + Changes directories */ +PHP_FUNCTION(ftp_exec) +{ + pval *arg1, *arg2; + ftpbuf_t *ftp; + + /* arg1 - ftp + * arg2 - command + */ + if ( ARG_COUNT(ht) != 2 || + getParameters(ht, 2, &arg1, &arg2) == FAILURE) + { + WRONG_PARAM_COUNT; + } + + convert_to_string(arg2); + + FTPBUF(ftp, arg1); + + /* change directories */ + if (!ftp_exec(ftp, arg2->value.str.val)) { + php_error(E_WARNING, "ftp_exec: %s", ftp->inbuf); RETURN_FALSE; } diff -u -r functions/php_ftp.h.orig functions/php_ftp.h --- functions/php_ftp.h.orig Sun Jan 9 12:06:00 2000 +++ functions/php_ftp.h Wed Feb 16 09:49:08 2000 @@ -55,6 +55,7 @@ PHP_FUNCTION(ftp_pwd); PHP_FUNCTION(ftp_cdup); PHP_FUNCTION(ftp_chdir); +PHP_FUNCTION(ftp_exec); PHP_FUNCTION(ftp_mkdir); PHP_FUNCTION(ftp_rmdir); PHP_FUNCTION(ftp_nlist); </pre>

« previous php.notes (#10207) next »