⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 php_ftp.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.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.               |   +----------------------------------------------------------------------+   | Authors: Andrew Skalski <askalski@chek.com>                          |   |          Stefan Esser <sesser@php.net> (resume functions)            |   +----------------------------------------------------------------------+ *//* $Id: php_ftp.c,v 1.74.2.15.2.2 2007/01/01 09:46:42 sebastian Exp $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#ifdef NETWARE#ifdef USE_WINSOCK#include <novsock2.h>#else#ifndef NEW_LIBC#include <sys/socket.h>#endif#endif#endif#if HAVE_FTP#include "ext/standard/info.h"#include "ext/standard/file.h"#include "php_ftp.h"#include "ftp.h"static int	le_ftpbuf;#define le_ftpbuf_name "FTP Buffer"function_entry php_ftp_functions[] = {	PHP_FE(ftp_connect,			NULL)#ifdef HAVE_OPENSSL_EXT	PHP_FE(ftp_ssl_connect,		NULL)#endif		PHP_FE(ftp_login,			NULL)	PHP_FE(ftp_pwd,				NULL)	PHP_FE(ftp_cdup,			NULL)	PHP_FE(ftp_chdir,			NULL)	PHP_FE(ftp_exec,			NULL)	PHP_FE(ftp_mkdir,			NULL)	PHP_FE(ftp_rmdir,			NULL)	PHP_FE(ftp_nlist,			NULL)	PHP_FE(ftp_rawlist,			NULL)	PHP_FE(ftp_systype,			NULL)	PHP_FE(ftp_pasv,			NULL)	PHP_FE(ftp_get,				NULL)	PHP_FE(ftp_fget,			NULL)	PHP_FE(ftp_put,				NULL)	PHP_FE(ftp_fput,			NULL)	PHP_FE(ftp_size,			NULL)	PHP_FE(ftp_mdtm,			NULL)	PHP_FE(ftp_rename,			NULL)	PHP_FE(ftp_delete,			NULL)	PHP_FE(ftp_site,			NULL)	PHP_FE(ftp_close,			NULL)	PHP_FE(ftp_set_option,		NULL)	PHP_FE(ftp_get_option,		NULL)	PHP_FE(ftp_nb_fget,			NULL)	PHP_FE(ftp_nb_get,			NULL)	PHP_FE(ftp_nb_continue,		NULL)	PHP_FE(ftp_nb_put,			NULL)	PHP_FE(ftp_nb_fput,			NULL)	PHP_FALIAS(ftp_quit, ftp_close, NULL)	{NULL, NULL, NULL}};zend_module_entry php_ftp_module_entry = {    STANDARD_MODULE_HEADER,	"ftp",	php_ftp_functions,	PHP_MINIT(ftp),	NULL,	NULL,	NULL,	PHP_MINFO(ftp),    NO_VERSION_YET,	STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_FTPZEND_GET_MODULE(php_ftp)#endifstatic void ftp_destructor_ftpbuf(zend_rsrc_list_entry *rsrc TSRMLS_DC){	ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr;	ftp_close(ftp);}PHP_MINIT_FUNCTION(ftp){	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_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);	REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);	REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);	REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);	REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);	REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);	return SUCCESS;}PHP_MINFO_FUNCTION(ftp){	php_info_print_table_start();	php_info_print_table_row(2, "FTP support", "enabled");	php_info_print_table_end();}#define	XTYPE(xtype, mode)	{ \								if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \									php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mode must be FTP_ASCII or FTP_BINARY"); \									RETURN_FALSE; \								} \								xtype = mode; \							}/* {{{ proto resource ftp_connect(string host [, int port [, int timeout]])   Opens a FTP stream */PHP_FUNCTION(ftp_connect){	ftpbuf_t	*ftp;	char		*host;	int		host_len;	long 		port = 0;	long		timeout_sec = FTP_DEFAULT_TIMEOUT;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {		return;	}	if (timeout_sec <= 0) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");		RETURN_FALSE;	}	/* connect */	ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC);	if (ftp == NULL) {		RETURN_FALSE;	}	/* autoseek for resuming */	ftp->autoseek = FTP_DEFAULT_AUTOSEEK;#ifdef HAVE_OPENSSL_EXT	/* disable ssl */	ftp->use_ssl = 0;#endif	ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);}/* }}} */#ifdef HAVE_OPENSSL_EXT/* {{{ proto resource ftp_ssl_connect(string host [, int port [, int timeout]])   Opens a FTP-SSL stream */PHP_FUNCTION(ftp_ssl_connect){	ftpbuf_t	*ftp;	char		*host;	int		host_len;	long		port = 0;	long		timeout_sec = FTP_DEFAULT_TIMEOUT;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {		return;	}	if (timeout_sec <= 0) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");		RETURN_FALSE;	}	/* connect */	ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC);	if (ftp == NULL) {		RETURN_FALSE;	}	/* autoseek for resuming */	ftp->autoseek = FTP_DEFAULT_AUTOSEEK;	/* enable ssl */	ftp->use_ssl = 1;	ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);}/* }}} */#endif/* {{{ proto bool ftp_login(resource stream, string username, string password)   Logs into the FTP server */PHP_FUNCTION(ftp_login){	zval 		*z_ftp;	ftpbuf_t	*ftp;	char *user, *pass;	int user_len, pass_len;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	/* log in */	if (!ftp_login(ftp, user, pass TSRMLS_CC)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto string ftp_pwd(resource stream)   Returns the present working directory */PHP_FUNCTION(ftp_pwd){	zval 		*z_ftp;	ftpbuf_t	*ftp;	const char	*pwd;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	pwd = ftp_pwd(ftp);	if (pwd == NULL) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_STRING((char*) pwd, 1);}/* }}} *//* {{{ proto bool ftp_cdup(resource stream)   Changes to the parent directory */PHP_FUNCTION(ftp_cdup){	zval 		*z_ftp;	ftpbuf_t	*ftp;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	if (!ftp_cdup(ftp)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto bool ftp_chdir(resource stream, string directory)   Changes directories */PHP_FUNCTION(ftp_chdir){	zval		*z_ftp;	ftpbuf_t	*ftp;	char		*dir;	int			dir_len;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	/* change directories */	if (!ftp_chdir(ftp, dir)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto bool ftp_exec(resource stream, string command)   Requests execution of a program on the FTP server */PHP_FUNCTION(ftp_exec){	pval		*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 serverside command */	if (!ftp_exec(ftp, cmd)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ 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){	zval		*z_ftp;	ftpbuf_t	*ftp;	char		*dir, *tmp;	int			dir_len;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	/* create directorie */	if (NULL == (tmp = ftp_mkdir(ftp, dir))) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_STRING(tmp, 0);}/* }}} *//* {{{ proto bool ftp_rmdir(resource stream, string directory)   Removes a directory */PHP_FUNCTION(ftp_rmdir){	zval		*z_ftp;	ftpbuf_t	*ftp;	char		*dir;	int			dir_len;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	/* remove directorie */	if (!ftp_rmdir(ftp, dir)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto array ftp_nlist(resource stream, string directory)   Returns an array of filenames in the given directory */PHP_FUNCTION(ftp_nlist){	zval		*z_ftp;	ftpbuf_t	*ftp;	char		**nlist, **ptr, *dir;	int			dir_len;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);	/* get list of files */	if (NULL == (nlist = ftp_nlist(ftp, dir TSRMLS_CC))) {		RETURN_FALSE;	}	array_init(return_value);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -