ID: 21053 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Closed Bug Type: FTP related Operating System: FreeBSD 4.6.2 PHP Version: 4.2.3 New Comment:
This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. Rather than modify the behavior of ftp_exec(), I've added a new function ftp_raw() which has the added feature of being able to send arbitrary commands rather than just "SITE EXEC" commands. This new function will return NULL on failure or an array of response strings on success. I'll also update the ftp_exec() documentation to reflect the boolean return value. Previous Comments: ------------------------------------------------------------------------ [2002-12-16 15:37:03] [EMAIL PROTECTED] What you sent in your report is not a documentation problem, but an FTP related feature request. Because you includeded C source code too, I recategorize this as FTP related. Also modified summary ------------------------------------------------------------------------ [2002-12-16 15:24:20] [EMAIL PROTECTED] The ftp_exec routine in PHP 4.2.3 doesn't work as advertised in the manual, returning true or false status rather than command output. I've written a replacement version of the routine, which has worked well for me under FreeBSD 4.6.2. My changes were: in ftp.h: /* exec a command [special features], return response on success, false on error */ char** ftp_exec(ftpbuf_t *ftp, const char *cmd); (change return type from int to char**) in php_ftp.c: /* {{{ proto array ftp_exec(resource stream, string cmd) Returns the results of a system command as an array of output lines */ PHP_FUNCTION(ftp_exec) { pval *z_ftp; ftpbuf_t *ftp; char **llist, **ptr, *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); /* get raw command output */ if (NULL == (llist = ftp_exec(ftp, cmd))) { RETURN_FALSE; } array_init(return_value); for (ptr = llist; *ptr; ptr++) add_next_index_string(return_value, *ptr, 1); free(llist); } /* }}} */ Finally, in ftp.c: /* {{{ ftp_exec */ char** ftp_exec(ftpbuf_t *ftp, const char *cmd) { char **ret = NULL; char **entry; char *text; if (!ftp_type(ftp, FTPTYPE_ASCII)) return NULL; if (!ftp_putcmd(ftp, "SITE EXEC", cmd)) return NULL; ret = malloc(FTP_BUFSIZE * sizeof(char*)); if (ret == NULL) { perror("malloc"); return NULL; } entry = ret; text = (char*) (ret + 100); *entry = text; while(1) { if (!ftp_readline(ftp)) { free(ret); return NULL; } strcpy(text, ftp->inbuf); text += strlen(ftp->inbuf) + 1; *++entry = text; /* Break out when the end-tag is found */ if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') { break; } } *entry = NULL; return ret; } /* }}} */ I had to make, make install, etc, then restart the httpd to pick up the new version. The code works for me, returning an array of the raw output of a command, one line per array entry. We needed the output from "site exec quota -v", which from our mailserver comes prefixed with intermediate status levels: 200-quota -v 200-Disk quotas for jqpublic (uid 12345): 200-Filesystem usage quota limit timeleft ... ... 200 (end of 'quota -v') It requires some extra parsing at the application end, but I figured it's safer to have to parse, than to have to figure out all the possible styles of output ahead of time. PDM ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21053&edit=1