From: Andrew Skalski Date: Mon, 4 Oct 1999 18:30:37 +0000 (+0000) Subject: Added delete and rename functions. X-Git-Tag: php-4.0b3_RC2~332 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1f8b8a9a2d907c8c4a9020b4fa766ed467cb096;p=php Added delete and rename functions. --- diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index b83f34b8a6..ecacee627c 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -632,6 +632,38 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) } +int +ftp_delete(ftpbuf_t *ftp, const char *path) +{ + if (ftp == NULL) + return 0; + + fprintf(ftp->fp, "DELE %s\r\n", path); + if (!ftp_getresp(ftp) || ftp->resp != 250) + return 0; + + return 1; +} + + +int +ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) +{ + if (ftp == NULL) + return 0; + + fprintf(ftp->fp, "RNFR %s\r\n", src); + if (!ftp_getresp(ftp) || ftp->resp != 350) + return 0; + + fprintf(ftp->fp, "RNTO %s\r\n", dest); + if (!ftp_getresp(ftp) || ftp->resp != 250) + return 0; + + return 1; +} + + /* static functions */ databuf_t* diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index ddfe9aa118..a92c1c9fbe 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -140,7 +140,13 @@ int ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, /* returns the size of the given file, or -1 on error */ int ftp_size(ftpbuf_t *ftp, const char *path); -/* returns the last modified time of the given file, or -1 on error */ +/* returns the last modified time of the given file, or -1 on error */ time_t ftp_mdtm(ftpbuf_t *ftp, const char *path); +/* renames a file on the server */ +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); + #endif diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index 2307b0aa9c..07f8ff59a6 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -64,6 +64,8 @@ function_entry php3_ftp_functions[] = { PHP_FE(ftp_fput, NULL) PHP_FE(ftp_size, NULL) PHP_FE(ftp_mdtm, NULL) + PHP_FE(ftp_rename, NULL) + PHP_FE(ftp_delete, NULL) PHP_FE(ftp_quit, NULL) {NULL, NULL, NULL} }; @@ -714,6 +716,66 @@ PHP_FUNCTION(ftp_mdtm) } /* }}} */ +/* {{{ proto int ftp_rename(int stream, string src, string dest) + Renames the given file to a new path */ +PHP_FUNCTION(ftp_rename) +{ + pval *arg1, *arg2, *arg3; + ftpbuf_t *ftp; + + /* arg1 - ftp + * arg2 - src + * arg3 - dest + */ + if ( ARG_COUNT(ht) != 3 || + getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) + { + WRONG_PARAM_COUNT; + } + + FTPBUF(ftp, arg1); + convert_to_string(arg2); + convert_to_string(arg3); + + /* rename the file */ + if (!ftp_rename(ftp, arg2->value.str.val, arg3->value.str.val)) { + php_error(E_WARNING, "ftp_rename: %s", ftp->inbuf); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int ftp_delete(int stream, string path) + Deletes a file */ +PHP_FUNCTION(ftp_delete) +{ + pval *arg1, *arg2; + ftpbuf_t *ftp; + + /* arg1 - ftp + * arg2 - path + */ + if ( ARG_COUNT(ht) != 2 || + getParameters(ht, 2, &arg1, &arg2) == FAILURE) + { + WRONG_PARAM_COUNT; + } + + FTPBUF(ftp, arg1); + convert_to_string(arg2); + + /* delete the file */ + if (!ftp_delete(ftp, arg2->value.str.val)) { + php_error(E_WARNING, "ftp_delete: %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 1515b79725..7da896cc8d 100644 --- a/ext/ftp/php_ftp.h +++ b/ext/ftp/php_ftp.h @@ -66,6 +66,8 @@ PHP_FUNCTION(ftp_put); PHP_FUNCTION(ftp_fput); PHP_FUNCTION(ftp_size); PHP_FUNCTION(ftp_mdtm); +PHP_FUNCTION(ftp_rename); +PHP_FUNCTION(ftp_delete); PHP_FUNCTION(ftp_quit); #define phpext_ftp_ptr php3_ftp_module_ptr