]> granicus.if.org Git - php/commitdiff
added the ftp_site() function
authorAndrew Skalski <askalski@php.net>
Tue, 22 Feb 2000 20:50:00 +0000 (20:50 +0000)
committerAndrew Skalski <askalski@php.net>
Tue, 22 Feb 2000 20:50:00 +0000 (20:50 +0000)
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c
ext/ftp/php_ftp.h

index 916e706c724c09366a5f34df6688f4c782af7008..1a5e807e8b77d6890d83d0e11adbe4c3215b63e8 100644 (file)
@@ -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
index b202981d9a4ac39902cfee9f0a075b15a6cadf92..562c2dbfeae475eb2bb93688d0cde40aa56e38a9 100644 (file)
@@ -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
index f96cc21a3c5b305a78495330eadaf00364526ff7..a4f843ffb84f8a7ccc0c24294cbe66d6ebebb645 100644 (file)
@@ -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)
index 8e1a08ec838cabe43849332cae24c98f92336eca..08bece1b30e6d80f6d30b3e03b82e8a69782d47e 100644 (file)
@@ -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