pollita         Sun Jan 26 21:54:12 2003 EDT

  Modified files:              
    /php4/ext/ftp       ftp.c ftp.h php_ftp.c php_ftp.h 
  Log:
  Feature Request #21748.  Added function ftp_chmod().
  
  
Index: php4/ext/ftp/ftp.c
diff -u php4/ext/ftp/ftp.c:1.73 php4/ext/ftp/ftp.c:1.74
--- php4/ext/ftp/ftp.c:1.73     Tue Jan  7 08:02:43 2003
+++ php4/ext/ftp/ftp.c  Sun Jan 26 21:54:12 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ftp.c,v 1.73 2003/01/07 13:02:43 iliaa Exp $ */
+/* $Id: ftp.c,v 1.74 2003/01/27 02:54:12 pollita Exp $ */
 
 #include "php.h"
 
@@ -534,6 +534,31 @@
        return 1;
 }
 /* }}} */
+
+/* {{{ ftp_chmod
+ */
+int
+ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename)
+{
+       char buffer[1024];
+
+       if (ftp == NULL) {
+               return 0;
+       }
+
+       sprintf(buffer, "CHMOD %o %s", mode, filename);
+
+       if (!ftp_putcmd(ftp, "SITE", buffer)) {
+               return 0;
+       }
+
+       if (!ftp_getresp(ftp) || ftp->resp != 200) {
+               return 0;
+       }
+       return 1;
+}
+/* }}} */
+
 
 /* {{{ ftp_nlist
  */
Index: php4/ext/ftp/ftp.h
diff -u php4/ext/ftp/ftp.h:1.33 php4/ext/ftp/ftp.h:1.34
--- php4/ext/ftp/ftp.h:1.33     Tue Jan  7 08:02:43 2003
+++ php4/ext/ftp/ftp.h  Sun Jan 26 21:54:12 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ftp.h,v 1.33 2003/01/07 13:02:43 iliaa Exp $ */
+/* $Id: ftp.h,v 1.34 2003/01/27 02:54:12 pollita Exp $ */
 
 #ifndef        FTP_H
 #define        FTP_H
@@ -134,6 +134,9 @@
 
 /* removes a directory, return true on success, false on error */
 int            ftp_rmdir(ftpbuf_t *ftp, const char *dir);
+
+/* Set permissions on a file */
+int            ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename);
 
 /* returns a NULL-terminated array of filenames in the given path
  * or NULL on error.  the return array must be freed (but don't
Index: php4/ext/ftp/php_ftp.c
diff -u php4/ext/ftp/php_ftp.c:1.79 php4/ext/ftp/php_ftp.c:1.80
--- php4/ext/ftp/php_ftp.c:1.79 Tue Jan  7 08:02:43 2003
+++ php4/ext/ftp/php_ftp.c      Sun Jan 26 21:54:12 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ftp.c,v 1.79 2003/01/07 13:02:43 iliaa Exp $ */
+/* $Id: php_ftp.c,v 1.80 2003/01/27 02:54:12 pollita Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -58,6 +58,7 @@
        PHP_FE(ftp_exec,                        NULL)
        PHP_FE(ftp_mkdir,                       NULL)
        PHP_FE(ftp_rmdir,                       NULL)
+       PHP_FE(ftp_chmod,                       NULL)
        PHP_FE(ftp_nlist,                       NULL)
        PHP_FE(ftp_rawlist,                     NULL)
        PHP_FE(ftp_systype,                     NULL)
@@ -377,6 +378,30 @@
        }
 
        RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto int ftp_chmod(resource stream, int mode, string filename)
+   Sets permissions on a file */
+PHP_FUNCTION(ftp_chmod)
+{
+       zval            *z_ftp;
+       ftpbuf_t        *ftp;
+       char            *filename;
+       int                     mode, filename_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &z_ftp, &mode, 
+&filename, &filename_len) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
+
+       if (!ftp_chmod(ftp, mode, filename)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
+               RETURN_FALSE;
+       }
+
+       RETURN_LONG(mode);
 }
 /* }}} */
 
Index: php4/ext/ftp/php_ftp.h
diff -u php4/ext/ftp/php_ftp.h:1.22 php4/ext/ftp/php_ftp.h:1.23
--- php4/ext/ftp/php_ftp.h:1.22 Tue Dec 31 11:06:38 2002
+++ php4/ext/ftp/php_ftp.h      Sun Jan 26 21:54:12 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ftp.h,v 1.22 2002/12/31 16:06:38 sebastian Exp $ */
+/* $Id: php_ftp.h,v 1.23 2003/01/27 02:54:12 pollita Exp $ */
 
 #ifndef        _INCLUDED_FTP_H
 #define        _INCLUDED_FTP_H
@@ -45,6 +45,7 @@
 PHP_FUNCTION(ftp_exec);
 PHP_FUNCTION(ftp_mkdir);
 PHP_FUNCTION(ftp_rmdir);
+PHP_FUNCTION(ftp_chmod);
 PHP_FUNCTION(ftp_nlist);
 PHP_FUNCTION(ftp_rawlist);
 PHP_FUNCTION(ftp_systype);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to