1999-09-20 22:10:25 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2012-01-01 21:15:04 +08:00
|
|
|
| Copyright (c) 1997-2012 The PHP Group |
|
1999-09-20 22:10:25 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2001-06-20 05:25:53 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2001-06-20 05:25:53 +08:00
|
|
|
| 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> |
|
2002-07-26 21:03:08 +08:00
|
|
|
| Stefan Esser <sesser@php.net> (resume functions) |
|
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"
|
|
|
|
|
2004-09-27 22:25:13 +08:00
|
|
|
#if defined(NETWARE) && defined(USE_WINSOCK)
|
2002-09-05 18:13:27 +08:00
|
|
|
#include <novsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2003-12-07 00:12:10 +08:00
|
|
|
#if HAVE_OPENSSL_EXT
|
|
|
|
# include <openssl/ssl.h>
|
2003-02-28 15:25:15 +08:00
|
|
|
#endif
|
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
#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"
|
|
|
|
|
2010-04-27 07:53:30 +08:00
|
|
|
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
|
|
|
|
2006-06-12 04:03:05 +08:00
|
|
|
/* {{{ arginfo */
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, host)
|
|
|
|
ZEND_ARG_INFO(0, port)
|
|
|
|
ZEND_ARG_INFO(0, timeout)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
#if HAVE_OPENSSL_EXT
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_ssl_connect, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, host)
|
|
|
|
ZEND_ARG_INFO(0, port)
|
|
|
|
ZEND_ARG_INFO(0, timeout)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_login, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, username)
|
|
|
|
ZEND_ARG_INFO(0, password)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_pwd, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_cdup, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_chdir, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, directory)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_exec, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, command)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_raw, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, command)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_mkdir, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, directory)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_rmdir, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, directory)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_chmod, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, filename)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_alloc, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, size)
|
|
|
|
ZEND_ARG_INFO(1, response)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_nlist, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, directory)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_rawlist, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, directory)
|
|
|
|
ZEND_ARG_INFO(0, recursive)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_systype, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fget, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, fp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, resumepos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fget, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, fp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, resumepos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_pasv, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, pasv)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_get, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, local_file)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, resume_pos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_get, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, local_file)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, resume_pos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_nb_continue, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fput, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, fp)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, startpos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fput, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, fp)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, startpos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_put, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, local_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, startpos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_put, 0, 0, 4)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, remote_file)
|
|
|
|
ZEND_ARG_INFO(0, local_file)
|
|
|
|
ZEND_ARG_INFO(0, mode)
|
|
|
|
ZEND_ARG_INFO(0, startpos)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_size, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, filename)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_mdtm, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, filename)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_rename, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, src)
|
|
|
|
ZEND_ARG_INFO(0, dest)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_delete, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, file)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_site, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, cmd)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_close, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_set_option, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, option)
|
|
|
|
ZEND_ARG_INFO(0, value)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ftp_get_option, 0)
|
|
|
|
ZEND_ARG_INFO(0, ftp)
|
|
|
|
ZEND_ARG_INFO(0, option)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
/* }}} */
|
2003-09-19 01:36:08 +08:00
|
|
|
|
2007-09-28 02:00:48 +08:00
|
|
|
const zend_function_entry php_ftp_functions[] = {
|
2006-06-12 04:03:05 +08:00
|
|
|
PHP_FE(ftp_connect, arginfo_ftp_connect)
|
2003-12-07 00:12:10 +08:00
|
|
|
#if HAVE_OPENSSL_EXT
|
2006-06-12 04:03:05 +08:00
|
|
|
PHP_FE(ftp_ssl_connect, arginfo_ftp_ssl_connect)
|
2002-10-03 19:33:05 +08:00
|
|
|
#endif
|
2006-06-12 04:03:05 +08:00
|
|
|
PHP_FE(ftp_login, arginfo_ftp_login)
|
|
|
|
PHP_FE(ftp_pwd, arginfo_ftp_pwd)
|
|
|
|
PHP_FE(ftp_cdup, arginfo_ftp_cdup)
|
|
|
|
PHP_FE(ftp_chdir, arginfo_ftp_chdir)
|
|
|
|
PHP_FE(ftp_exec, arginfo_ftp_exec)
|
|
|
|
PHP_FE(ftp_raw, arginfo_ftp_raw)
|
|
|
|
PHP_FE(ftp_mkdir, arginfo_ftp_mkdir)
|
|
|
|
PHP_FE(ftp_rmdir, arginfo_ftp_rmdir)
|
|
|
|
PHP_FE(ftp_chmod, arginfo_ftp_chmod)
|
|
|
|
PHP_FE(ftp_alloc, arginfo_ftp_alloc)
|
|
|
|
PHP_FE(ftp_nlist, arginfo_ftp_nlist)
|
|
|
|
PHP_FE(ftp_rawlist, arginfo_ftp_rawlist)
|
|
|
|
PHP_FE(ftp_systype, arginfo_ftp_systype)
|
|
|
|
PHP_FE(ftp_pasv, arginfo_ftp_pasv)
|
|
|
|
PHP_FE(ftp_get, arginfo_ftp_get)
|
|
|
|
PHP_FE(ftp_fget, arginfo_ftp_fget)
|
|
|
|
PHP_FE(ftp_put, arginfo_ftp_put)
|
|
|
|
PHP_FE(ftp_fput, arginfo_ftp_fput)
|
|
|
|
PHP_FE(ftp_size, arginfo_ftp_size)
|
|
|
|
PHP_FE(ftp_mdtm, arginfo_ftp_mdtm)
|
|
|
|
PHP_FE(ftp_rename, arginfo_ftp_rename)
|
|
|
|
PHP_FE(ftp_delete, arginfo_ftp_delete)
|
|
|
|
PHP_FE(ftp_site, arginfo_ftp_site)
|
|
|
|
PHP_FE(ftp_close, arginfo_ftp_close)
|
|
|
|
PHP_FE(ftp_set_option, arginfo_ftp_set_option)
|
|
|
|
PHP_FE(ftp_get_option, arginfo_ftp_get_option)
|
|
|
|
PHP_FE(ftp_nb_fget, arginfo_ftp_nb_fget)
|
|
|
|
PHP_FE(ftp_nb_get, arginfo_ftp_nb_get)
|
|
|
|
PHP_FE(ftp_nb_continue, arginfo_ftp_nb_continue)
|
|
|
|
PHP_FE(ftp_nb_put, arginfo_ftp_nb_put)
|
|
|
|
PHP_FE(ftp_nb_fput, arginfo_ftp_nb_fput)
|
|
|
|
PHP_FALIAS(ftp_quit, ftp_close, arginfo_ftp_close)
|
2011-07-25 19:35:02 +08:00
|
|
|
PHP_FE_END
|
1999-09-20 22:10:25 +08:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2003-12-07 00:12:10 +08:00
|
|
|
#if COMPILE_DL_FTP
|
2000-05-02 10:02:18 +08:00
|
|
|
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);
|
2002-07-12 04:29:53 +08:00
|
|
|
REGISTER_LONG_CONSTANT("FTP_ASCII", FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
|
2002-01-02 22:58:17 +08:00
|
|
|
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);
|
2002-07-26 21:03:08 +08:00
|
|
|
REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
|
2002-01-02 22:58:17 +08:00
|
|
|
REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
|
2002-07-26 21:03:08 +08:00
|
|
|
REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
|
2002-07-27 06:00:25 +08:00
|
|
|
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);
|
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-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mode must be FTP_ASCII or FTP_BINARY"); \
|
2002-01-02 06:15:22 +08:00
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
|
|
|
xtype = mode; \
|
|
|
|
}
|
1999-09-27 22:07:09 +08:00
|
|
|
|
|
|
|
|
2003-08-08 00:02:28 +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;
|
2003-03-07 07:07:28 +08:00
|
|
|
int host_len;
|
|
|
|
long port = 0;
|
2002-01-02 22:58:17 +08:00
|
|
|
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-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-09-20 22:10:25 +08:00
|
|
|
/* connect */
|
2003-02-15 04:15:11 +08:00
|
|
|
if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
|
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-07-26 21:03:08 +08:00
|
|
|
/* autoseek for resuming */
|
|
|
|
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
|
2003-12-07 00:12:10 +08:00
|
|
|
#if HAVE_OPENSSL_EXT
|
2002-10-03 19:33:05 +08:00
|
|
|
/* disable ssl */
|
|
|
|
ftp->use_ssl = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-12-07 00:12:10 +08:00
|
|
|
#if HAVE_OPENSSL_EXT
|
2003-08-08 00:03:17 +08:00
|
|
|
/* {{{ proto resource ftp_ssl_connect(string host [, int port [, int timeout]])
|
2002-10-03 19:33:05 +08:00
|
|
|
Opens a FTP-SSL stream */
|
|
|
|
PHP_FUNCTION(ftp_ssl_connect)
|
|
|
|
{
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
char *host;
|
2003-03-07 07:07:28 +08:00
|
|
|
int host_len;
|
|
|
|
long port = 0;
|
2002-10-03 19:33:05 +08:00
|
|
|
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 */
|
2003-02-15 04:15:11 +08:00
|
|
|
if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
|
2002-10-03 19:33:05 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* autoseek for resuming */
|
|
|
|
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
|
|
|
|
/* enable ssl */
|
|
|
|
ftp->use_ssl = 1;
|
2002-07-26 21:03:08 +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-10-03 19:33:05 +08:00
|
|
|
#endif
|
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 */
|
2003-01-07 11:44:12 +08:00
|
|
|
if (!ftp_login(ftp, user, pass TSRMLS_CC)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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
|
|
|
|
2003-02-15 04:15:11 +08:00
|
|
|
if (!(pwd = ftp_pwd(ftp))) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-01-02 06:15:22 +08:00
|
|
|
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)
|
|
|
|
{
|
2005-12-06 10:28:41 +08:00
|
|
|
zval *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-07-26 21:03:08 +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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-01-31 12:54:57 +08:00
|
|
|
/* {{{ 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);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
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))) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-01-07 10:47:24 +08:00
|
|
|
RETURN_STRING(tmp, 0);
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-01-27 10:54:12 +08:00
|
|
|
/* {{{ proto int ftp_chmod(resource stream, int mode, string filename)
|
|
|
|
Sets permissions on a file */
|
|
|
|
PHP_FUNCTION(ftp_chmod)
|
|
|
|
{
|
|
|
|
zval *z_ftp;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
char *filename;
|
2003-03-10 23:52:10 +08:00
|
|
|
int filename_len;
|
|
|
|
long mode;
|
2003-01-27 10:54:12 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlp", &z_ftp, &mode, &filename, &filename_len) == FAILURE) {
|
2003-01-27 10:54:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
|
2003-01-28 03:51:50 +08:00
|
|
|
if (!ftp_chmod(ftp, mode, filename, filename_len)) {
|
2003-01-27 10:54:12 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(mode);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-09-19 01:36:08 +08:00
|
|
|
/* {{{ proto bool ftp_alloc(resource stream, int size[, &response])
|
|
|
|
Attempt to allocate space on the remote FTP server */
|
|
|
|
PHP_FUNCTION(ftp_alloc)
|
|
|
|
{
|
|
|
|
zval *z_ftp, *zresponse = NULL;
|
|
|
|
ftpbuf_t *ftp;
|
2004-02-26 04:16:27 +08:00
|
|
|
long size, ret;
|
2003-09-19 01:36:08 +08:00
|
|
|
char *response = NULL;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &z_ftp, &size, &zresponse) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
|
|
|
|
ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
|
|
|
|
if (response) {
|
|
|
|
zval_dtor(zresponse);
|
|
|
|
ZVAL_STRING(zresponse, response, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
int dir_len;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &dir, &dir_len) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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 */
|
2003-01-07 11:44:12 +08:00
|
|
|
if (NULL == (nlist = ftp_nlist(ftp, dir TSRMLS_CC))) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2003-01-07 10:47:24 +08:00
|
|
|
for (ptr = nlist; *ptr; ptr++) {
|
1999-09-20 22:10:25 +08:00
|
|
|
add_next_index_string(return_value, *ptr, 1);
|
2003-01-07 10:47:24 +08:00
|
|
|
}
|
|
|
|
efree(nlist);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-07-04 21:48:48 +08:00
|
|
|
/* {{{ proto array ftp_rawlist(resource stream, string directory [, bool recursive])
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
int dir_len;
|
2002-07-10 05:42:07 +08:00
|
|
|
zend_bool recursive = 0;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2002-07-04 21:48:48 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &z_ftp, &dir, &dir_len, &recursive) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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 */
|
2003-01-07 11:44:12 +08:00
|
|
|
if (NULL == (llist = ftp_list(ftp, dir, recursive TSRMLS_CC))) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2003-01-07 10:47:24 +08:00
|
|
|
for (ptr = llist; *ptr; ptr++) {
|
1999-09-20 22:10:25 +08:00
|
|
|
add_next_index_string(return_value, *ptr, 1);
|
2003-01-07 10:47:24 +08:00
|
|
|
}
|
|
|
|
efree(llist);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
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
|
|
|
|
2002-01-02 06:15:22 +08:00
|
|
|
if (NULL == (syst = ftp_syst(ftp))) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_STRING((char*) syst, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* {{{ proto bool ftp_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
|
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;
|
2003-03-10 23:52:10 +08:00
|
|
|
int file_len;
|
|
|
|
long mode, resumepos=0;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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-08-25 18:10:23 +08:00
|
|
|
php_stream_from_zval(stream, &z_file);
|
2002-01-02 06:15:22 +08:00
|
|
|
XTYPE(xtype, mode);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
resumepos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && resumepos) {
|
|
|
|
/* if autoresume is wanted seek to end */
|
|
|
|
if (resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
php_stream_seek(stream, 0, SEEK_END);
|
|
|
|
resumepos = php_stream_tell(stream);
|
|
|
|
} else {
|
|
|
|
php_stream_seek(stream, resumepos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 21:02:43 +08:00
|
|
|
if (!ftp_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-15 23:29:46 +08:00
|
|
|
/* {{{ proto int ftp_nb_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
|
2002-07-27 06:00:25 +08:00
|
|
|
Retrieves a file from the FTP server asynchronly and writes it to an open file */
|
2002-10-03 17:10:24 +08:00
|
|
|
PHP_FUNCTION(ftp_nb_fget)
|
2002-07-27 06:00:25 +08:00
|
|
|
{
|
|
|
|
zval *z_ftp, *z_file;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
|
|
|
php_stream *stream;
|
|
|
|
char *file;
|
2003-03-10 23:52:10 +08:00
|
|
|
int file_len, ret;
|
|
|
|
long mode, resumepos=0;
|
2002-07-27 06:00:25 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2002-09-25 23:46:47 +08:00
|
|
|
php_stream_from_zval(stream, &z_file);
|
2002-07-27 06:00:25 +08:00
|
|
|
XTYPE(xtype, mode);
|
|
|
|
|
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
resumepos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && resumepos) {
|
|
|
|
/* if autoresume is wanted seek to end */
|
|
|
|
if (resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
php_stream_seek(stream, 0, SEEK_END);
|
|
|
|
resumepos = php_stream_tell(stream);
|
|
|
|
} else {
|
|
|
|
php_stream_seek(stream, resumepos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
ftp->direction = 0; /* recv */
|
|
|
|
ftp->closestream = 0; /* do not close */
|
|
|
|
|
2003-01-07 11:44:12 +08:00
|
|
|
if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
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-07-26 21:03:08 +08:00
|
|
|
/* {{{ proto bool ftp_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
|
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-07-26 21:03:08 +08:00
|
|
|
php_stream *outstream;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *local, *remote;
|
2003-03-10 23:52:10 +08:00
|
|
|
int local_len, remote_len;
|
|
|
|
long mode, resumepos=0;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
2002-07-26 21:03:08 +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-07-26 21:03:08 +08:00
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
resumepos = 0;
|
|
|
|
}
|
|
|
|
|
2005-03-11 07:37:45 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
mode = FTPTYPE_IMAGE;
|
|
|
|
#endif
|
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
if (ftp->autoseek && resumepos) {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
|
2002-07-26 21:03:08 +08:00
|
|
|
if (outstream == NULL) {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
|
2002-07-26 21:03:08 +08:00
|
|
|
}
|
|
|
|
if (outstream != NULL) {
|
|
|
|
/* if autoresume is wanted seek to end */
|
|
|
|
if (resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
php_stream_seek(outstream, 0, SEEK_END);
|
|
|
|
resumepos = php_stream_tell(outstream);
|
|
|
|
} else {
|
|
|
|
php_stream_seek(outstream, resumepos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (outstream == NULL) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-01-07 21:02:43 +08:00
|
|
|
if (!ftp_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) {
|
2002-07-26 21:03:08 +08:00
|
|
|
php_stream_close(outstream);
|
2003-11-05 04:56:47 +08:00
|
|
|
VCWD_UNLINK(local);
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-26 21:03:08 +08:00
|
|
|
RETURN_FALSE;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(outstream);
|
2002-12-06 14:07:40 +08:00
|
|
|
RETURN_TRUE;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-10-03 17:10:24 +08:00
|
|
|
/* {{{ proto int ftp_nb_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
|
|
|
|
Retrieves a file from the FTP server nbhronly and writes it to a local file */
|
|
|
|
PHP_FUNCTION(ftp_nb_get)
|
2002-07-27 06:00:25 +08:00
|
|
|
{
|
|
|
|
zval *z_ftp;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
|
|
|
php_stream *outstream;
|
|
|
|
char *local, *remote;
|
2003-03-10 23:52:10 +08:00
|
|
|
int local_len, remote_len, ret;
|
|
|
|
long mode, resumepos=0;
|
2002-07-27 06:00:25 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
XTYPE(xtype, mode);
|
|
|
|
|
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
resumepos = 0;
|
|
|
|
}
|
2005-03-11 07:37:45 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
mode = FTPTYPE_IMAGE;
|
|
|
|
#endif
|
2002-07-27 06:00:25 +08:00
|
|
|
if (ftp->autoseek && resumepos) {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
|
2002-07-27 06:00:25 +08:00
|
|
|
if (outstream == NULL) {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
|
2002-07-27 06:00:25 +08:00
|
|
|
}
|
|
|
|
if (outstream != NULL) {
|
|
|
|
/* if autoresume is wanted seek to end */
|
|
|
|
if (resumepos == PHP_FTP_AUTORESUME) {
|
|
|
|
php_stream_seek(outstream, 0, SEEK_END);
|
|
|
|
resumepos = php_stream_tell(outstream);
|
|
|
|
} else {
|
|
|
|
php_stream_seek(outstream, resumepos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-04-27 07:53:30 +08:00
|
|
|
outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
|
2002-07-27 06:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (outstream == NULL) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
ftp->direction = 0; /* recv */
|
|
|
|
ftp->closestream = 1; /* do close */
|
|
|
|
|
2003-01-07 11:44:12 +08:00
|
|
|
if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
|
2002-07-27 06:00:25 +08:00
|
|
|
php_stream_close(outstream);
|
2003-11-05 04:56:47 +08:00
|
|
|
VCWD_UNLINK(local);
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_LONG(PHP_FTP_FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == PHP_FTP_FINISHED) {
|
|
|
|
php_stream_close(outstream);
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-10-03 17:10:24 +08:00
|
|
|
/* {{{ proto int ftp_nb_continue(resource stream)
|
|
|
|
Continues retrieving/sending a file nbronously */
|
|
|
|
PHP_FUNCTION(ftp_nb_continue)
|
2002-07-27 06:00:25 +08:00
|
|
|
{
|
|
|
|
zval *z_ftp;
|
|
|
|
ftpbuf_t *ftp;
|
2003-01-07 10:47:24 +08:00
|
|
|
int ret;
|
2002-07-27 06:00:25 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-10-03 17:10:24 +08:00
|
|
|
if (!ftp->nb) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no nbronous transfer to continue.");
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_LONG(PHP_FTP_FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->direction) {
|
2003-01-07 21:02:43 +08:00
|
|
|
ret=ftp_nb_continue_write(ftp TSRMLS_CC);
|
2002-07-27 06:00:25 +08:00
|
|
|
} else {
|
2003-01-07 21:02:43 +08:00
|
|
|
ret=ftp_nb_continue_read(ftp TSRMLS_CC);
|
2002-07-27 06:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != PHP_FTP_MOREDATA && ftp->closestream) {
|
|
|
|
php_stream_close(ftp->stream);
|
|
|
|
}
|
|
|
|
|
2002-08-25 18:10:23 +08:00
|
|
|
if (ret == PHP_FTP_FAILED) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-27 06:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* {{{ proto bool ftp_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
|
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;
|
2003-03-10 23:52:10 +08:00
|
|
|
int remote_len;
|
|
|
|
long mode, startpos=0;
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream *stream;
|
2002-01-02 06:15:22 +08:00
|
|
|
char *remote;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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-09-25 23:46:47 +08:00
|
|
|
php_stream_from_zval(stream, &z_file);
|
2002-01-02 06:15:22 +08:00
|
|
|
XTYPE(xtype, mode);
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && startpos) {
|
|
|
|
/* if autoresume is wanted ask for remote size */
|
|
|
|
if (startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = ftp_size(ftp, remote);
|
|
|
|
if (startpos < 0) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startpos) {
|
|
|
|
php_stream_seek(stream, startpos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 21:02:43 +08:00
|
|
|
if (!ftp_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
1999-09-27 22:07:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-15 23:29:46 +08:00
|
|
|
/* {{{ proto int ftp_nb_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
|
2002-10-03 17:10:24 +08:00
|
|
|
Stores a file from an open file to the FTP server nbronly */
|
|
|
|
PHP_FUNCTION(ftp_nb_fput)
|
2002-07-27 06:00:25 +08:00
|
|
|
{
|
|
|
|
zval *z_ftp, *z_file;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
2003-03-10 23:52:10 +08:00
|
|
|
int remote_len, ret;
|
|
|
|
long mode, startpos=0;
|
2002-07-27 06:00:25 +08:00
|
|
|
php_stream *stream;
|
|
|
|
char *remote;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
2002-09-25 23:46:47 +08:00
|
|
|
php_stream_from_zval(stream, &z_file);
|
2002-07-27 06:00:25 +08:00
|
|
|
XTYPE(xtype, mode);
|
|
|
|
|
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && startpos) {
|
|
|
|
/* if autoresume is wanted ask for remote size */
|
|
|
|
if (startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = ftp_size(ftp, remote);
|
|
|
|
if (startpos < 0) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startpos) {
|
|
|
|
php_stream_seek(stream, startpos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
ftp->direction = 1; /* send */
|
|
|
|
ftp->closestream = 0; /* do not close */
|
|
|
|
|
2003-01-07 11:44:12 +08:00
|
|
|
if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) == PHP_FTP_FAILED)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* {{{ proto bool ftp_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
|
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;
|
2003-03-10 23:52:10 +08:00
|
|
|
int remote_len, local_len;
|
|
|
|
long mode, startpos=0;
|
2003-01-07 10:47:24 +08:00
|
|
|
php_stream *instream;
|
1999-09-20 22:10:25 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
return;
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
2002-07-26 21:03:08 +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
|
|
|
|
2010-04-27 07:53:30 +08:00
|
|
|
if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
|
1999-09-20 22:10:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2002-07-26 21:03:08 +08:00
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && startpos) {
|
|
|
|
/* if autoresume is wanted ask for remote size */
|
|
|
|
if (startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = ftp_size(ftp, remote);
|
|
|
|
if (startpos < 0) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startpos) {
|
|
|
|
php_stream_seek(instream, startpos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 21:02:43 +08:00
|
|
|
if (!ftp_put(ftp, remote, instream, xtype, startpos TSRMLS_CC)) {
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(instream);
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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-07-27 06:00:25 +08:00
|
|
|
|
2003-06-15 23:29:46 +08:00
|
|
|
/* {{{ proto int ftp_nb_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
|
2002-07-27 06:00:25 +08:00
|
|
|
Stores a file on the FTP server */
|
2002-10-03 17:10:24 +08:00
|
|
|
PHP_FUNCTION(ftp_nb_put)
|
2002-07-27 06:00:25 +08:00
|
|
|
{
|
|
|
|
zval *z_ftp;
|
|
|
|
ftpbuf_t *ftp;
|
|
|
|
ftptype_t xtype;
|
|
|
|
char *remote, *local;
|
2003-03-10 23:52:10 +08:00
|
|
|
int remote_len, local_len, ret;
|
|
|
|
long mode, startpos=0;
|
2003-01-07 10:47:24 +08:00
|
|
|
php_stream *instream;
|
2002-07-27 06:00:25 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
|
2002-07-27 06:00:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
|
|
|
XTYPE(xtype, mode);
|
|
|
|
|
2010-04-27 07:53:30 +08:00
|
|
|
if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
|
2002-07-27 06:00:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore autoresume if autoseek is switched off */
|
|
|
|
if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ftp->autoseek && startpos) {
|
|
|
|
/* if autoresume is wanted ask for remote size */
|
|
|
|
if (startpos == PHP_FTP_AUTORESUME) {
|
|
|
|
startpos = ftp_size(ftp, remote);
|
|
|
|
if (startpos < 0) {
|
|
|
|
startpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startpos) {
|
|
|
|
php_stream_seek(instream, startpos, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
ftp->direction = 1; /* send */
|
|
|
|
ftp->closestream = 1; /* do close */
|
|
|
|
|
2003-01-07 11:44:12 +08:00
|
|
|
ret = ftp_nb_put(ftp, remote, instream, xtype, startpos TSRMLS_CC);
|
2002-07-27 06:00:25 +08:00
|
|
|
|
|
|
|
if (ret != PHP_FTP_MOREDATA) {
|
|
|
|
php_stream_close(instream);
|
|
|
|
}
|
|
|
|
|
2002-08-25 18:10:23 +08:00
|
|
|
if (ret == PHP_FTP_FAILED) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2002-07-27 06:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
int file_len;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
int file_len;
|
1999-09-27 22:07:09 +08:00
|
|
|
|
2011-06-07 05:28:16 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
|
2002-01-02 06:15:22 +08:00
|
|
|
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;
|
2003-01-07 10:47:24 +08:00
|
|
|
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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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;
|
2003-01-07 10:47:24 +08:00
|
|
|
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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", 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;
|
2003-01-07 10:47:24 +08:00
|
|
|
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)) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
|
2000-02-23 04:50:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-15 23:29:46 +08:00
|
|
|
/* {{{ proto bool 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
|
|
|
|
2003-04-03 08:55:56 +08:00
|
|
|
ftp_quit(ftp);
|
|
|
|
|
2002-07-31 04:37:59 +08:00
|
|
|
RETURN_BOOL(zend_list_delete(Z_LVAL_P(z_ftp)) == SUCCESS);
|
1999-09-20 22:10:25 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2002-07-26 21:03:08 +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)
|
|
|
|
{
|
2003-01-07 10:47:24 +08:00
|
|
|
zval *z_ftp, *z_value;
|
|
|
|
long option;
|
2002-01-02 22:58:17 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-07-26 21:03:08 +08:00
|
|
|
|
2002-01-02 22:58:17 +08:00
|
|
|
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-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option TIMEOUT_SEC expects value of type long, %s given",
|
|
|
|
zend_zval_type_name(z_value));
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (Z_LVAL_P(z_value) <= 0) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
|
2002-01-02 22:58:17 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
ftp->timeout_sec = Z_LVAL_P(z_value);
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
2002-07-26 21:03:08 +08:00
|
|
|
case PHP_FTP_OPT_AUTOSEEK:
|
|
|
|
if (Z_TYPE_P(z_value) != IS_BOOL) {
|
2002-08-25 18:10:23 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option AUTOSEEK expects value of type boolean, %s given",
|
|
|
|
zend_zval_type_name(z_value));
|
2002-07-26 21:03:08 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
ftp->autoseek = Z_LVAL_P(z_value);
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
2002-01-02 22:58:17 +08:00
|
|
|
default:
|
2003-08-29 03:17:34 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", 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)
|
|
|
|
{
|
2003-01-07 10:47:24 +08:00
|
|
|
zval *z_ftp;
|
|
|
|
long option;
|
2002-01-02 22:58:17 +08:00
|
|
|
ftpbuf_t *ftp;
|
2002-07-26 21:03:08 +08:00
|
|
|
|
2002-01-02 22:58:17 +08:00
|
|
|
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;
|
2002-07-26 21:03:08 +08:00
|
|
|
case PHP_FTP_OPT_AUTOSEEK:
|
|
|
|
RETURN_BOOL(ftp->autoseek);
|
2003-01-07 10:47:24 +08:00
|
|
|
break;
|
2002-01-02 22:58:17 +08:00
|
|
|
default:
|
2003-08-29 03:17:34 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", 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:
|
|
|
|
*/
|