]> granicus.if.org Git - php/commitdiff
- Added ftp_exec to the ftp functions (thanks to <jhennebicq@i-d.net>)
authorDerick Rethans <derick@php.net>
Wed, 13 Sep 2000 22:00:31 +0000 (22:00 +0000)
committerDerick Rethans <derick@php.net>
Wed, 13 Sep 2000 22:00:31 +0000 (22:00 +0000)
@ Added ftp_exec to the ftp functions (thanks to <jhennebicq@i-d.net>)
@ (Derick)

ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c
ext/ftp/php_ftp.h

index 45b01e799d1c3322f1d5687569cd7f94ec23147b..a750265fccb7289f9bd365db85df42333b53baeb 100644 (file)
@@ -314,6 +314,20 @@ ftp_pwd(ftpbuf_t *ftp)
 }
 
 
+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)
 {
index ea9a25d047f5dcb7341ac6fc81222d201249a09e..2e3d1bc8d035785851b28222171a4ffaef0457f2 100644 (file)
@@ -100,6 +100,9 @@ const char* ftp_syst(ftpbuf_t *ftp);
 /* returns the present working directory (NULL on error) */
 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);
+
 /* changes directories, return true on success, false on error */
 int            ftp_chdir(ftpbuf_t *ftp, const char *dir);
 
index 233d7079728fa32e529287de027190bc4fe091c9..061b2aac6cbbedbe4ea4f554b422f195b3737b51 100644 (file)
@@ -48,6 +48,7 @@ function_entry php_ftp_functions[] = {
        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)
@@ -272,6 +273,36 @@ PHP_FUNCTION(ftp_chdir)
        /* 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;
        }
 
index e602fe79fc49f596417e9cdcd7313a331acc9456..79a8e1664297a895db33c4e9ca35c19313d902ea 100644 (file)
@@ -45,6 +45,7 @@ PHP_FUNCTION(ftp_login);
 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);