cvs: /php3/functions ftp.c ftp.h php_ftp.c php_ftp.h

From: Date: Mon, 04 Oct 1999 18:45:09 +0000
Subject: cvs: /php3/functions ftp.c ftp.h php_ftp.c php_ftp.h
Groups: php.dev 
Request: Send a blank email to php-dev+get-11505@lists.php.net to get a copy of this message
askalski Mon Oct 4 14:45:09 1999 EDT Modified files: /php3/functions ftp.c ftp.h php_ftp.c php_ftp.h Log: Added delete/rename functionality. Index: php3/functions/ftp.c diff -u php3/functions/ftp.c:1.8 php3/functions/ftp.c:1.9 --- php3/functions/ftp.c:1.8 Mon Sep 27 10:09:24 1999 +++ php3/functions/ftp.c Mon Oct 4 14:45:08 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ftp.c,v 1.8 1999/09/27 14:09:24 askalski Exp $ */ +/* $Id: ftp.c,v 1.9 1999/10/04 18:45:08 askalski Exp $ */ #include "php.h" @@ -629,6 +629,38 @@ stamp = mktime(&tm); return stamp; +} + + +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; } Index: php3/functions/ftp.h diff -u php3/functions/ftp.h:1.5 php3/functions/ftp.h:1.6 --- php3/functions/ftp.h:1.5 Mon Sep 27 10:09:25 1999 +++ php3/functions/ftp.h Mon Oct 4 14:45:08 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ftp.h,v 1.5 1999/09/27 14:09:25 askalski Exp $ */ +/* $Id: ftp.h,v 1.6 1999/10/04 18:45:08 askalski Exp $ */ #ifndef _FTP_H #define _FTP_H @@ -140,7 +140,13 @@ /* 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 Index: php3/functions/php_ftp.c diff -u php3/functions/php_ftp.c:1.5 php3/functions/php_ftp.c:1.6 --- php3/functions/php_ftp.c:1.5 Mon Sep 27 10:09:25 1999 +++ php3/functions/php_ftp.c Mon Oct 4 14:45:08 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ftp.c,v 1.5 1999/09/27 14:09:25 askalski Exp $ */ +/* $Id: php_ftp.c,v 1.6 1999/10/04 18:45:08 askalski Exp $ */ #include "php.h" @@ -64,6 +64,8 @@ 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} }; @@ -711,6 +713,66 @@ /* get file mod time */ RETURN_LONG(ftp_mdtm(ftp, arg2->value.str.val)); +} +/* }}} */ + +/* {{{ 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; } /* }}} */ Index: php3/functions/php_ftp.h diff -u php3/functions/php_ftp.h:1.4 php3/functions/php_ftp.h:1.5 --- php3/functions/php_ftp.h:1.4 Mon Sep 27 10:09:25 1999 +++ php3/functions/php_ftp.h Mon Oct 4 14:45:08 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ftp.h,v 1.4 1999/09/27 14:09:25 askalski Exp $ */ +/* $Id: php_ftp.h,v 1.5 1999/10/04 18:45:08 askalski Exp $ */ #ifndef _INCLUDED_FTP_H #define _INCLUDED_FTP_H @@ -66,6 +66,8 @@ 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

« previous php.dev (#11505) next »