diff options
author | Sara Golemon <pollita@php.net> | 2003-01-27 02:54:12 +0000 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2003-01-27 02:54:12 +0000 |
commit | 761fa96412960d942e8767df7a3874f84371db34 (patch) | |
tree | 68ae95d92bd9e9d2fe8e8313ab22cdac0da30652 /ext/ftp | |
parent | e9833ff497d2d8c47e426edaffda4f12cd3c8797 (diff) | |
download | php-git-761fa96412960d942e8767df7a3874f84371db34.tar.gz |
Feature Request #21748. Added function ftp_chmod().
Diffstat (limited to 'ext/ftp')
-rw-r--r-- | ext/ftp/ftp.c | 25 | ||||
-rw-r--r-- | ext/ftp/ftp.h | 3 | ||||
-rw-r--r-- | ext/ftp/php_ftp.c | 25 | ||||
-rw-r--r-- | ext/ftp/php_ftp.h | 1 |
4 files changed, 54 insertions, 0 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index ef27ed0df2..96e2a7f299 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -535,6 +535,31 @@ ftp_rmdir(ftpbuf_t *ftp, const char *dir) } /* }}} */ +/* {{{ 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 */ char** diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index dd6be94c8b..35bf12bffb 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -135,6 +135,9 @@ char* ftp_mkdir(ftpbuf_t *ftp, const char *dir); /* 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 * free the array elements) diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index 3b218385fd..b8fc548b1e 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -58,6 +58,7 @@ function_entry php_ftp_functions[] = { 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) @@ -380,6 +381,30 @@ PHP_FUNCTION(ftp_rmdir) } /* }}} */ +/* {{{ 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); +} +/* }}} */ + /* {{{ proto array ftp_nlist(resource stream, string directory) Returns an array of filenames in the given directory */ PHP_FUNCTION(ftp_nlist) diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h index 10c87b7b0a..f203987b23 100644 --- a/ext/ftp/php_ftp.h +++ b/ext/ftp/php_ftp.h @@ -45,6 +45,7 @@ PHP_FUNCTION(ftp_chdir); 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); |