Browse Source

Add ftp_raw() to send raw command strings to an FTP server.

PHP-5
Sara Golemon 24 years ago
parent
commit
81797baed4
  1. 21
      ext/ftp/ftp.c
  2. 3
      ext/ftp/ftp.h
  3. 21
      ext/ftp/php_ftp.c
  4. 1
      ext/ftp/php_ftp.h

21
ext/ftp/ftp.c

@ -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 /* {{{ ftp_chdir
*/ */
int int

3
ext/ftp/ftp.h

@ -121,6 +121,9 @@ const char* ftp_pwd(ftpbuf_t *ftp);
/* exec a command [special features], return true on success, false on error */ /* exec a command [special features], return true on success, false on error */
int ftp_exec(ftpbuf_t *ftp, const char *cmd); 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 */ /* changes directories, return true on success, false on error */
int ftp_chdir(ftpbuf_t *ftp, const char *dir); int ftp_chdir(ftpbuf_t *ftp, const char *dir);

21
ext/ftp/php_ftp.c

@ -56,6 +56,7 @@ function_entry php_ftp_functions[] = {
PHP_FE(ftp_cdup, NULL) PHP_FE(ftp_cdup, NULL)
PHP_FE(ftp_chdir, NULL) PHP_FE(ftp_chdir, NULL)
PHP_FE(ftp_exec, NULL) PHP_FE(ftp_exec, NULL)
PHP_FE(ftp_raw, NULL)
PHP_FE(ftp_mkdir, NULL) PHP_FE(ftp_mkdir, NULL)
PHP_FE(ftp_rmdir, NULL) PHP_FE(ftp_rmdir, NULL)
PHP_FE(ftp_chmod, 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) /* {{{ proto string ftp_mkdir(resource stream, string directory)
Creates a directory and returns the absolute path for the new directory or false on error */ Creates a directory and returns the absolute path for the new directory or false on error */
PHP_FUNCTION(ftp_mkdir) PHP_FUNCTION(ftp_mkdir)

1
ext/ftp/php_ftp.h

@ -43,6 +43,7 @@ PHP_FUNCTION(ftp_pwd);
PHP_FUNCTION(ftp_cdup); PHP_FUNCTION(ftp_cdup);
PHP_FUNCTION(ftp_chdir); PHP_FUNCTION(ftp_chdir);
PHP_FUNCTION(ftp_exec); PHP_FUNCTION(ftp_exec);
PHP_FUNCTION(ftp_raw);
PHP_FUNCTION(ftp_mkdir); PHP_FUNCTION(ftp_mkdir);
PHP_FUNCTION(ftp_rmdir); PHP_FUNCTION(ftp_rmdir);
PHP_FUNCTION(ftp_chmod); PHP_FUNCTION(ftp_chmod);

Loading…
Cancel
Save