}
+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*
/* 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
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}
};
}
/* }}} */
+/* {{{ 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)