]> granicus.if.org Git - php/commitdiff
Add ftp_raw() to send raw command strings to an FTP server.
authorSara Golemon <pollita@php.net>
Fri, 31 Jan 2003 04:54:57 +0000 (04:54 +0000)
committerSara Golemon <pollita@php.net>
Fri, 31 Jan 2003 04:54:57 +0000 (04:54 +0000)
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c
ext/ftp/php_ftp.h

index 0180c4f5986afb21829691b7d72921077c1aeebd..8cafa790e01333d948bfb59d097fc6c00cfd49d6 100644 (file)
@@ -443,6 +443,27 @@ ftp_exec(ftpbuf_t *ftp, const char *cmd)
 }
 /* }}} */
 
+/* {{{ ftp_raw
+ */
+void
+ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value)
+{
+       if (ftp == NULL || cmd == NULL) {
+               RETURN_NULL();
+       }
+       if (!ftp_putcmd(ftp, cmd, NULL)) {
+               RETURN_NULL();
+       }
+       array_init(return_value);
+       while (ftp_readline(ftp)) {
+               add_next_index_string(return_value, ftp->inbuf, 1);
+               if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
+                       return;
+               }
+       }
+}
+/* }}} */
+
 /* {{{ ftp_chdir
  */
 int
index 19233a5d6c624d0524f8d566a53e245778b4aa2c..2fffe08f9456ea0f882a49252a401576188a60f2 100644 (file)
@@ -121,6 +121,9 @@ const char* ftp_pwd(ftpbuf_t *ftp);
 /* exec a command [special features], return true on success, false on error */
 int    ftp_exec(ftpbuf_t *ftp, const char *cmd);
 
+/* send a raw ftp command, return response as a hashtable, NULL on error */
+void   ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value);
+
 /* changes directories, return true on success, false on error */
 int            ftp_chdir(ftpbuf_t *ftp, const char *dir);
 
index d43211ad39b921a62eb2248d880060b8759a42c4..2cc8d198ab8b40f43059b533978aba68f350c058 100644 (file)
@@ -56,6 +56,7 @@ function_entry php_ftp_functions[] = {
        PHP_FE(ftp_cdup,                        NULL)
        PHP_FE(ftp_chdir,                       NULL)
        PHP_FE(ftp_exec,                        NULL)
+       PHP_FE(ftp_raw,                         NULL)
        PHP_FE(ftp_mkdir,                       NULL)
        PHP_FE(ftp_rmdir,                       NULL)
        PHP_FE(ftp_chmod,                       NULL)
@@ -331,6 +332,26 @@ PHP_FUNCTION(ftp_exec)
 }
 /* }}} */
 
+/* {{{ proto array ftp_raw(resource stream, string command)
+   Sends a literal command to the FTP server */
+PHP_FUNCTION(ftp_raw)
+{
+       zval            *z_ftp;
+       ftpbuf_t        *ftp;
+       char            *cmd;
+       int                     cmd_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
+               return;
+       }
+
+       ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
+
+       /* execute arbitrary ftp command */
+       ftp_raw(ftp, cmd, return_value);
+}
+/* }}} */
+
 /* {{{ proto string ftp_mkdir(resource stream, string directory)
    Creates a directory and returns the absolute path for the new directory or false on error */
 PHP_FUNCTION(ftp_mkdir)
index f203987b23d1b8f9c647c9bdac2d3efa60da56d1..47e5ba1b34b775aadf0fd4c69769061403881154 100644 (file)
@@ -43,6 +43,7 @@ PHP_FUNCTION(ftp_pwd);
 PHP_FUNCTION(ftp_cdup);
 PHP_FUNCTION(ftp_chdir);
 PHP_FUNCTION(ftp_exec);
+PHP_FUNCTION(ftp_raw);
 PHP_FUNCTION(ftp_mkdir);
 PHP_FUNCTION(ftp_rmdir);
 PHP_FUNCTION(ftp_chmod);