1999-09-20 22:10:25 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| Copyright (c) 1997-2002 The PHP Group |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-06-20 05:25:53 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Authors: Andrew Skalski <askalski@chek.com> |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-09-23 00:07:41 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
#include "php.h"
|
|
|
|
|
|
|
|
#if HAVE_FTP
|
|
|
|
|
2000-10-08 19:45:18 +08:00
|
|
|
#include "ext/standard/info.h"
|
1999-12-12 18:51:13 +08:00
|
|
|
#include "ext/standard/file.h"
|
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
#include "php_ftp.h"
|
|
|
|
#include "ftp.h"
|
|
|
|
|
|
|
|
static int le_ftpbuf;
|
2002-01-02 06:15:22 +08:00
|
|
|
#define le_ftpbuf_name "FTP Buffer"
|
1999-09-20 22:10:25 +08:00
|
|
|
|
1999-12-18 05:34:28 +08:00
|
|
|
function_entry php_ftp_functions[] = {
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FE(ftp_connect, NULL)
|
|
|
|
PHP_FE(ftp_login, NULL)
|
|
|
|
PHP_FE(ftp_pwd, NULL)
|
|
|
|
PHP_FE(ftp_cdup, NULL)
|
|
|
|
PHP_FE(ftp_chdir, NULL)
|
2000-09-14 06:00:31 +08:00
|
|
|
PHP_FE(ftp_exec, NULL)
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FE(ftp_mkdir, NULL)
|
|
|
|
PHP_FE(ftp_rmdir, NULL)
|
|
|
|
PHP_FE(ftp_nlist, NULL)
|
1999-09-20 23:40:22 +08:00
|
|
|
PHP_FE(ftp_rawlist, NULL)
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FE(ftp_systype, NULL)
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FE(ftp_pasv, NULL)
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FE(ftp_get, NULL)
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FE(ftp_fget, NULL)
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FE(ftp_put, NULL)
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FE(ftp_fput, NULL)
|
|
|
|
PHP_FE(ftp_size, NULL)
|
|
|
|
PHP_FE(ftp_mdtm, NULL)
|
1999-10-05 02:30:37 +08:00
|
|
|
PHP_FE(ftp_rename, NULL)
|
|
|
|
PHP_FE(ftp_delete, NULL)
|
2000-02-23 04:50:00 +08:00
|
|
|
PHP_FE(ftp_site, NULL)
|
2002-01-02 06:15:22 +08:00
|
|
|
PHP_FE(ftp_close, NULL)
|
2002-01-02 22:58:17 +08:00
|
|
|
PHP_FE(ftp_set_option, NULL)
|
|
|
|
PHP_FE(ftp_get_option, NULL)
|
2002-01-02 06:15:22 +08:00
|
|
|
PHP_FALIAS(ftp_quit, ftp_close, NULL)
|
1999-09-20 22:10:25 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
1999-12-18 05:34:28 +08:00
|
|
|
zend_module_entry php_ftp_module_entry = {
|
2001-10-12 07:33:59 +08:00
|
|
|
STANDARD_MODULE_HEADER,
|
2000-03-07 02:44:01 +08:00
|
|
|
"ftp",
|
1999-12-18 05:34:28 +08:00
|
|
|
php_ftp_functions,
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_MINIT(ftp),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2000-10-08 19:45:18 +08:00
|
|
|
PHP_MINFO(ftp),
|
2001-10-12 07:33:59 +08:00
|
|
|
NO_VERSION_YET,
|
1999-09-20 22:10:25 +08:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
|
2000-05-02 10:02:18 +08:00
|
|
|
#ifdef COMPILE_DL_FTP
|
|
|
|
ZEND_GET_MODULE(php_ftp)
|
|
|
|
#endif
|
|
|
|
|
2001-07-31 13:44:11 +08:00
|
|
|
static void ftp_destructor_ftpbuf(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
1999-09-20 22:10:25 +08:00
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr;
|
2001-07-31 13:44:11 +08:00
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
ftp_close(ftp);
|
|
|
|
}
|
|
|
|
|
1999-09-24 01:54:26 +08:00
|
|
|
PHP_MINIT_FUNCTION(ftp)
|
1999-09-20 22:10:25 +08:00
|
|
|
{
|
2002-01-02 22:58:17 +08:00
|
|
|
le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);
|
|
|
|
REGISTER_LONG_CONSTANT("FTP_ASCII", FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_LONG_CONSTANT("FTP_TEXT", FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_LONG_CONSTANT("FTP_IMAGE", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
|
1999-09-20 22:10:25 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-10-08 19:45:18 +08:00
|
|
|
PHP_MINFO_FUNCTION(ftp)
|
|
|
|
{
|
2001-07-30 14:18:13 +08:00
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_row(2, "FTP support", "enabled");
|
|
|
|
php_info_print_table_end();
|
2000-10-08 19:45:18 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
#define XTYPE(xtype, mode) { \
|
|
|
|
if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Mode must be FTP_ASCII or FTP_BINARY", get_active_function_name(TSRMLS_C)); \
|
2002-01-02 06:15:22 +08:00
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
|
|
|
xtype = mode; \
|
|
|
|
}
|
1999-09-27 22:07:09 +08:00
|
|
|
|
|
|
|
|
2002-01-02 23:01:15 +08:00
|
|
|
/* {{{ proto resource ftp_connect(string host [, int port [, int timeout)]])
|
2000-08-09 04:28:19 +08:00
|
|
|
Opens a FTP stream */
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FUNCTION(ftp_connect)
|
|
|
|
{
|
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *host;
|
2002-01-02 22:58:17 +08:00
|
|
|
int host_len, port = 0;
|
|
|
|
long timeout_sec = FTP_DEFAULT_TIMEOUT;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 22:58:17 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 22:58:17 +08:00
|
|
|
if (timeout_sec <= 0) {
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Timeout has to be greater than 0",
|
2002-01-02 22:58:17 +08:00
|
|
|
get_active_function_name(TSRMLS_C));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
/* connect */
|
2002-03-30 09:56:52 +08:00
|
|
|
ftp = ftp_open(host, (short)port, timeout_sec);
|
2002-01-02 06:15:22 +08:00
|
|
|
if (ftp == NULL) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
2002-01-02 06:15:22 +08:00
|
|
|
}
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_login(resource stream, string username, string password)
|
2000-07-14 04:55:22 +08:00
|
|
|
Logs into the FTP server */
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FUNCTION(ftp_login)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *user, *pass;
|
|
|
|
int user_len, pass_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
/* log in */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_login(ftp, user, pass)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto string ftp_pwd(resource stream)
|
2000-07-14 04:55:22 +08:00
|
|
|
Returns the present working directory */
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FUNCTION(ftp_pwd)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
const char *pwd;
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
pwd = ftp_pwd(ftp);
|
|
|
|
if (pwd == NULL) {
|
2002-01-02 06:15:22 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_STRING((char*) pwd, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_cdup(resource stream)
|
1999-09-20 22:10:25 +08:00
|
|
|
Changes to the parent directory */
|
|
|
|
PHP_FUNCTION(ftp_cdup)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
if (!ftp_cdup(ftp)) {
|
2002-01-02 06:15:22 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_chdir(resource stream, string directory)
|
1999-09-20 22:10:25 +08:00
|
|
|
Changes directories */
|
|
|
|
PHP_FUNCTION(ftp_chdir)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *dir;
|
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
/* change directories */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_chdir(ftp, dir)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
|
|
|
RETURN_FALSE;
|
2000-09-14 06:00:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_exec(resource stream, string command)
|
2002-01-03 13:55:22 +08:00
|
|
|
Requests execution of a program on the FTP server */
|
2000-09-14 06:00:31 +08:00
|
|
|
PHP_FUNCTION(ftp_exec)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
pval *z_ftp;
|
2000-09-14 06:00:31 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *cmd;
|
|
|
|
int cmd_len;
|
2000-09-14 06:00:31 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
|
|
|
|
return;
|
2000-09-14 06:00:31 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2000-09-14 06:00:31 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* execute serverside command */
|
|
|
|
if (!ftp_exec(ftp, cmd)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 09:05:10 +08:00
|
|
|
/* {{{ proto string ftp_mkdir(resource stream, string directory)
|
2002-01-03 13:55:22 +08:00
|
|
|
Creates a directory and returns the absolute path for the new directory or false on error */
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FUNCTION(ftp_mkdir)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *dir, *tmp;
|
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* create directorie */
|
|
|
|
if (NULL == (tmp = ftp_mkdir(ftp, dir))) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
RETURN_STRING(tmp, 1);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_rmdir(resource stream, string directory)
|
1999-09-20 22:10:25 +08:00
|
|
|
Removes a directory */
|
|
|
|
PHP_FUNCTION(ftp_rmdir)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *dir;
|
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* remove directorie */
|
|
|
|
if (!ftp_rmdir(ftp, dir)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto array ftp_nlist(resource stream, string directory)
|
1999-09-20 22:10:25 +08:00
|
|
|
Returns an array of filenames in the given directory */
|
|
|
|
PHP_FUNCTION(ftp_nlist)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char **nlist, **ptr, *dir;
|
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
/* get list of files */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (NULL == (nlist = ftp_nlist(ftp, dir))) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
for (ptr = nlist; *ptr; ptr++)
|
|
|
|
add_next_index_string(return_value, *ptr, 1);
|
|
|
|
free(nlist);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto array ftp_rawlist(resource stream, string directory)
|
1999-09-20 22:10:25 +08:00
|
|
|
Returns a detailed listing of a directory as an array of output lines */
|
1999-09-20 23:40:22 +08:00
|
|
|
PHP_FUNCTION(ftp_rawlist)
|
1999-09-20 22:10:25 +08:00
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char **llist, **ptr, *dir;
|
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* get raw directory listing */
|
|
|
|
if (NULL == (llist = ftp_list(ftp, dir))) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
for (ptr = llist; *ptr; ptr++)
|
|
|
|
add_next_index_string(return_value, *ptr, 1);
|
|
|
|
free(llist);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto string ftp_systype(resource stream)
|
1999-09-20 22:10:25 +08:00
|
|
|
Returns the system type identifier */
|
|
|
|
PHP_FUNCTION(ftp_systype)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
const char *syst;
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
syst = ftp_syst(ftp);
|
2002-01-02 06:15:22 +08:00
|
|
|
if (NULL == (syst = ftp_syst(ftp))) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_STRING((char*) syst, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 08:42:11 +08:00
|
|
|
/* {{{ proto bool ftp_fget(resource stream, resource fp, string remote_file, int mode)
|
2000-07-14 04:55:22 +08:00
|
|
|
Retrieves a file from the FTP server and writes it to an open file */
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FUNCTION(ftp_fget)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp, *z_file;
|
1999-09-27 22:07:09 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream *stream;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *file;
|
|
|
|
int file_len, mode;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl", &z_ftp, &z_file, &file, &file_len, &mode) == FAILURE) {
|
|
|
|
return;
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2002-03-16 05:03:08 +08:00
|
|
|
ZEND_FETCH_RESOURCE(stream, php_stream*, &z_file, -1, "File-Handle", php_file_le_stream());
|
2002-01-02 06:15:22 +08:00
|
|
|
XTYPE(xtype, mode);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (!ftp_get(ftp, stream, file, xtype) || php_stream_error(stream)) {
|
2002-01-02 06:15:22 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (php_stream_error(stream)) {
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Error writing %s", get_active_function_name(TSRMLS_C), Z_STRVAL_P(z_file));
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_pasv(resource stream, bool pasv)
|
2000-07-14 04:55:22 +08:00
|
|
|
Turns passive mode on or off */
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FUNCTION(ftp_pasv)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-27 22:07:09 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
zend_bool pasv;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &z_ftp, &pasv) == FAILURE) {
|
|
|
|
return;
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_pasv(ftp, pasv ? 1 : 0)) {
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
2002-01-02 06:15:22 +08:00
|
|
|
}
|
1999-09-27 22:07:09 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_get(resource stream, string local_file, string remote_file, int mode)
|
2000-07-14 04:55:22 +08:00
|
|
|
Retrieves a file from the FTP server and writes it to a local file */
|
1999-09-20 22:10:25 +08:00
|
|
|
PHP_FUNCTION(ftp_get)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream * tmpstream, *outstream;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *local, *remote;
|
|
|
|
int local_len, remote_len, mode;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &z_ftp, &local, &local_len, &remote, &remote_len, &mode) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
2002-01-02 06:15:22 +08:00
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
XTYPE(xtype, mode);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
/* get to temporary file, so if there is an error, no existing
|
|
|
|
* file gets clobbered
|
|
|
|
*/
|
2002-03-16 05:03:08 +08:00
|
|
|
tmpstream = php_stream_fopen_tmpfile();
|
|
|
|
if (tmpstream == NULL) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (!ftp_get(ftp, tmpstream, remote, xtype) || php_stream_error(tmpstream)) {
|
|
|
|
php_stream_close(tmpstream);
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-18 06:50:59 +08:00
|
|
|
outstream = php_stream_fopen(local, "wb", NULL);
|
2002-03-16 05:03:08 +08:00
|
|
|
|
|
|
|
if (outstream == NULL) {
|
|
|
|
php_stream_close(tmpstream);
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Error opening %s", get_active_function_name(TSRMLS_C), local);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_rewind(tmpstream);
|
2002-03-16 10:48:35 +08:00
|
|
|
if (php_stream_copy_to_stream(tmpstream, outstream, PHP_STREAM_COPY_ALL) == 0) {
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Error writing %s", get_active_function_name(TSRMLS_C), local);
|
2002-03-16 05:03:08 +08:00
|
|
|
RETVAL_FALSE;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
else
|
|
|
|
RETVAL_TRUE;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(tmpstream);
|
|
|
|
php_stream_close(outstream);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 09:05:10 +08:00
|
|
|
/* {{{ proto bool ftp_fput(resource stream, string remote_file, resource fp, int mode)
|
2000-07-14 04:55:22 +08:00
|
|
|
Stores a file from an open file to the FTP server */
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FUNCTION(ftp_fput)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp, *z_file;
|
1999-09-27 22:07:09 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
2002-03-16 05:03:08 +08:00
|
|
|
int mode, remote_len;
|
|
|
|
php_stream *stream;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *remote;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &z_ftp, &remote, &remote_len, &z_file, &mode) == FAILURE) {
|
|
|
|
return;
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2002-03-16 05:03:08 +08:00
|
|
|
ZEND_FETCH_RESOURCE(stream, php_stream*, &z_file, -1, "File-Handle", php_file_le_stream());
|
2002-01-02 06:15:22 +08:00
|
|
|
XTYPE(xtype, mode);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (!ftp_put(ftp, remote, stream, xtype)) {
|
2002-01-02 06:15:22 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_put(resource stream, string remote_file, string local_file, int mode)
|
1999-09-20 22:10:25 +08:00
|
|
|
Stores a file on the FTP server */
|
|
|
|
PHP_FUNCTION(ftp_put)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *remote, *local;
|
|
|
|
int remote_len, local_len, mode;
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream * instream;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &z_ftp, &remote, &remote_len, &local, &local_len, &mode) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
2002-01-02 06:15:22 +08:00
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
XTYPE(xtype, mode);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-03-18 06:50:59 +08:00
|
|
|
instream = php_stream_fopen(local, "rb", NULL);
|
2002-03-16 05:03:08 +08:00
|
|
|
|
|
|
|
if (instream == NULL) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
|
|
|
|
if (!ftp_put(ftp, remote, instream, xtype) || php_stream_error(instream)) {
|
|
|
|
php_stream_close(instream);
|
2002-01-02 06:15:22 +08:00
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(instream);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto int ftp_size(resource stream, string filename)
|
2000-07-14 04:55:22 +08:00
|
|
|
Returns the size of the file, or -1 on error */
|
1999-09-27 22:07:09 +08:00
|
|
|
PHP_FUNCTION(ftp_size)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-27 22:07:09 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *file;
|
|
|
|
int file_len;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &file, &file_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
|
|
|
/* get file size */
|
2002-01-02 06:15:22 +08:00
|
|
|
RETURN_LONG(ftp_size(ftp, file));
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto int ftp_mdtm(resource stream, string filename)
|
1999-09-27 22:07:09 +08:00
|
|
|
Returns the last modification time of the file, or -1 on error */
|
|
|
|
PHP_FUNCTION(ftp_mdtm)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-09-27 22:07:09 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *file;
|
|
|
|
int file_len;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &file, &file_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
|
|
|
/* get file mod time */
|
2002-01-02 06:15:22 +08:00
|
|
|
RETURN_LONG(ftp_mdtm(ftp, file));
|
1999-09-27 22:07:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_rename(resource stream, string src, string dest)
|
1999-10-05 02:30:37 +08:00
|
|
|
Renames the given file to a new path */
|
|
|
|
PHP_FUNCTION(ftp_rename)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-10-05 02:30:37 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *src, *dest;
|
|
|
|
int src_len, dest_len;
|
1999-10-05 02:30:37 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &src, &src_len, &dest, &dest_len) == FAILURE) {
|
|
|
|
return;
|
1999-10-05 02:30:37 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-10-05 02:30:37 +08:00
|
|
|
|
|
|
|
/* rename the file */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_rename(ftp, src, dest)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-10-05 02:30:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_delete(resource stream, string file)
|
1999-10-05 02:30:37 +08:00
|
|
|
Deletes a file */
|
|
|
|
PHP_FUNCTION(ftp_delete)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
1999-10-05 02:30:37 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *file;
|
|
|
|
int file_len;
|
1999-10-05 02:30:37 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &file, &file_len) == FAILURE) {
|
|
|
|
return;
|
1999-10-05 02:30:37 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-10-05 02:30:37 +08:00
|
|
|
|
|
|
|
/* delete the file */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_delete(ftp, file)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
1999-10-05 02:30:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto bool ftp_site(resource stream, string cmd)
|
2000-02-23 04:50:00 +08:00
|
|
|
Sends a SITE command to the server */
|
|
|
|
PHP_FUNCTION(ftp_site)
|
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
2000-02-23 04:50:00 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *cmd;
|
|
|
|
int cmd_len;
|
2000-02-23 04:50:00 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
|
|
|
|
return;
|
2000-02-23 04:50:00 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2000-02-23 04:50:00 +08:00
|
|
|
|
|
|
|
/* send the site command */
|
2002-01-02 06:15:22 +08:00
|
|
|
if (!ftp_site(ftp, cmd)) {
|
|
|
|
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), ftp->inbuf);
|
2000-02-23 04:50:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
/* {{{ proto void ftp_close(resource stream)
|
1999-09-20 22:10:25 +08:00
|
|
|
Closes the FTP stream */
|
2002-01-02 06:15:22 +08:00
|
|
|
PHP_FUNCTION(ftp_close)
|
1999-09-20 22:10:25 +08:00
|
|
|
{
|
2002-01-02 06:15:22 +08:00
|
|
|
zval *z_ftp;
|
|
|
|
ftpbuf_t *ftp;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(z_ftp));
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2002-01-02 22:58:17 +08:00
|
|
|
|
|
|
|
/* {{{ proto bool ftp_set_option(resource stream, int option, mixed value)
|
2002-01-03 13:55:22 +08:00
|
|
|
Sets an FTP option */
|
2002-01-02 22:58:17 +08:00
|
|
|
PHP_FUNCTION(ftp_set_option)
|
|
|
|
{
|
|
|
|
zval *z_ftp, *z_value;
|
|
|
|
long option;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &z_ftp, &option, &z_value) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case PHP_FTP_OPT_TIMEOUT_SEC:
|
|
|
|
if (Z_TYPE_P(z_value) != IS_LONG) {
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Option TIMEOUT_SEC expects value of type long, %s given",
|
2002-01-03 22:32:36 +08:00
|
|
|
get_active_function_name(TSRMLS_C), zend_zval_type_name(z_value));
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (Z_LVAL_P(z_value) <= 0) {
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Timeout has to be greater than 0",
|
2002-01-02 22:58:17 +08:00
|
|
|
get_active_function_name(TSRMLS_C));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
ftp->timeout_sec = Z_LVAL_P(z_value);
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Unknown option '%d'", get_active_function_name(TSRMLS_C), option);
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto mixed ftp_get_option(resource stream, int option)
|
2002-01-03 13:55:22 +08:00
|
|
|
Gets an FTP option */
|
2002-01-02 22:58:17 +08:00
|
|
|
PHP_FUNCTION(ftp_get_option)
|
|
|
|
{
|
|
|
|
zval *z_ftp;
|
|
|
|
long option;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_ftp, &option) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case PHP_FTP_OPT_TIMEOUT_SEC:
|
|
|
|
RETURN_LONG(ftp->timeout_sec);
|
|
|
|
break;
|
|
|
|
default:
|
2002-06-27 14:49:02 +08:00
|
|
|
php_error(E_WARNING, "%s(): Unknown option '%d'", get_active_function_name(TSRMLS_C), option);
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-09-20 22:10:25 +08:00
|
|
|
|
|
|
|
#endif /* HAVE_FTP */
|
2001-10-12 07:33:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|