]> granicus.if.org Git - php/commitdiff
Added delete and rename functions.
authorAndrew Skalski <askalski@php.net>
Mon, 4 Oct 1999 18:30:37 +0000 (18:30 +0000)
committerAndrew Skalski <askalski@php.net>
Mon, 4 Oct 1999 18:30:37 +0000 (18:30 +0000)
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c
ext/ftp/php_ftp.h

index b83f34b8a6b9ffd025d62748dff08ef76860a64e..ecacee627caa4cbd0af2eb67893281841cf93914 100644 (file)
@@ -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*
index ddfe9aa1182ab64a333b1813a6a22a5dac89e465..a92c1c9fbe4c6bd58fa4e89d72ec2f96f9d6295a 100644 (file)
@@ -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
index 2307b0aa9c915f21340ad0e75516669d550d8695..07f8ff59a609fb4ee657b691c835097d522e5bb5 100644 (file)
@@ -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)
index 1515b79725dc53b6df0a344d2dae6bb57e4a00b1..7da896cc8d9a6b6ec61945c003ad50b6021bfcf3 100644 (file)
@@ -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