diff options
-rw-r--r-- | ext/ftp/ftp.c | 17 | ||||
-rw-r--r-- | ext/ftp/ftp.h | 3 | ||||
-rw-r--r-- | ext/ftp/php_ftp.c | 30 | ||||
-rw-r--r-- | ext/ftp/php_ftp.h | 1 |
4 files changed, 50 insertions, 1 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 916e706c72..1a5e807e8b 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -167,7 +167,7 @@ ftp_close(ftpbuf_t *ftp) { if (ftp == NULL) return NULL; - if (ftp->fd) + if (ftp->fd != -1) close(ftp->fd); ftp_gc(ftp); free(ftp); @@ -682,6 +682,21 @@ ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) return 1; } + +int +ftp_site(ftpbuf_t *ftp, const char *cmd) +{ + if (ftp == NULL) + return 0; + + if (!ftp_putcmd(ftp, "SITE", cmd)) + return 0; + if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) + return 0; + + return 1; +} + /* static functions */ int diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index b202981d9a..562c2dbfea 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -155,4 +155,7 @@ int ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest); /* deletes the file from the server */ int ftp_delete(ftpbuf_t *ftp, const char *path); +/* sends a SITE command to the server */ +int ftp_site(ftpbuf_t *ftp, const char *cmd); + #endif diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index f96cc21a3c..a4f843ffb8 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -62,6 +62,7 @@ function_entry php_ftp_functions[] = { PHP_FE(ftp_mdtm, NULL) PHP_FE(ftp_rename, NULL) PHP_FE(ftp_delete, NULL) + PHP_FE(ftp_site, NULL) PHP_FE(ftp_quit, NULL) {NULL, NULL, NULL} }; @@ -758,6 +759,35 @@ PHP_FUNCTION(ftp_delete) } /* }}} */ +/* {{{ proto int ftp_site(int stream, string cmd) + Sends a SITE command to the server */ +PHP_FUNCTION(ftp_site) +{ + pval *arg1, *arg2; + ftpbuf_t *ftp; + + /* arg1 - ftp + * arg2 - cmd + */ + if ( ARG_COUNT(ht) != 2 || + getParameters(ht, 2, &arg1, &arg2) == FAILURE) + { + WRONG_PARAM_COUNT; + } + + FTPBUF(ftp, arg1); + convert_to_string(arg2); + + /* send the site command */ + if (!ftp_site(ftp, arg2->value.str.val)) { + php_error(E_WARNING, "ftp_site: %s", ftp->inbuf); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto int ftp_quit(int stream) Closes the FTP stream */ PHP_FUNCTION(ftp_quit) diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h index 8e1a08ec83..08bece1b30 100644 --- a/ext/ftp/php_ftp.h +++ b/ext/ftp/php_ftp.h @@ -64,6 +64,7 @@ PHP_FUNCTION(ftp_size); PHP_FUNCTION(ftp_mdtm); PHP_FUNCTION(ftp_rename); PHP_FUNCTION(ftp_delete); +PHP_FUNCTION(ftp_site); PHP_FUNCTION(ftp_quit); #define phpext_ftp_ptr php_ftp_module_ptr |