PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/ftp - php_ftp.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 311 472 65.9 %
Date: 2015-03-01 Functions: 36 36 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andrew Skalski <askalski@chek.com>                          |
      16             :    |          Stefan Esser <sesser@php.net> (resume functions)            |
      17             :    +----------------------------------------------------------------------+
      18             :  */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : 
      28             : #if defined(NETWARE) && defined(USE_WINSOCK)
      29             : #include <novsock2.h>
      30             : #endif
      31             : 
      32             : #if HAVE_OPENSSL_EXT
      33             : # include <openssl/ssl.h>
      34             : #endif
      35             : 
      36             : #if HAVE_FTP
      37             : 
      38             : #include "ext/standard/info.h"
      39             : #include "ext/standard/file.h"
      40             : 
      41             : #include "php_ftp.h"
      42             : #include "ftp.h"
      43             : 
      44             : static int le_ftpbuf;
      45             : #define le_ftpbuf_name "FTP Buffer"
      46             : 
      47             : /* {{{ arginfo */
      48             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1)
      49             :         ZEND_ARG_INFO(0, host)
      50             :         ZEND_ARG_INFO(0, port)
      51             :         ZEND_ARG_INFO(0, timeout)
      52             : ZEND_END_ARG_INFO()
      53             : 
      54             : #if HAVE_OPENSSL_EXT
      55             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_ssl_connect, 0, 0, 1)
      56             :         ZEND_ARG_INFO(0, host)
      57             :         ZEND_ARG_INFO(0, port)
      58             :         ZEND_ARG_INFO(0, timeout)
      59             : ZEND_END_ARG_INFO()
      60             : #endif
      61             : 
      62             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_login, 0)
      63             :         ZEND_ARG_INFO(0, ftp)
      64             :         ZEND_ARG_INFO(0, username)
      65             :         ZEND_ARG_INFO(0, password)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_pwd, 0)
      69             :         ZEND_ARG_INFO(0, ftp)
      70             : ZEND_END_ARG_INFO()
      71             : 
      72             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_cdup, 0)
      73             :         ZEND_ARG_INFO(0, ftp)
      74             : ZEND_END_ARG_INFO()
      75             : 
      76             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_chdir, 0)
      77             :         ZEND_ARG_INFO(0, ftp)
      78             :         ZEND_ARG_INFO(0, directory)
      79             : ZEND_END_ARG_INFO()
      80             : 
      81             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_exec, 0)
      82             :         ZEND_ARG_INFO(0, ftp)
      83             :         ZEND_ARG_INFO(0, command)
      84             : ZEND_END_ARG_INFO()
      85             : 
      86             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_raw, 0)
      87             :         ZEND_ARG_INFO(0, ftp)
      88             :         ZEND_ARG_INFO(0, command)
      89             : ZEND_END_ARG_INFO()
      90             : 
      91             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_mkdir, 0)
      92             :         ZEND_ARG_INFO(0, ftp)
      93             :         ZEND_ARG_INFO(0, directory)
      94             : ZEND_END_ARG_INFO()
      95             : 
      96             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_rmdir, 0)
      97             :         ZEND_ARG_INFO(0, ftp)
      98             :         ZEND_ARG_INFO(0, directory)
      99             : ZEND_END_ARG_INFO()
     100             : 
     101             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_chmod, 0)
     102             :         ZEND_ARG_INFO(0, ftp)
     103             :         ZEND_ARG_INFO(0, mode)
     104             :         ZEND_ARG_INFO(0, filename)
     105             : ZEND_END_ARG_INFO()
     106             : 
     107             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_alloc, 0, 0, 2)
     108             :         ZEND_ARG_INFO(0, ftp)
     109             :         ZEND_ARG_INFO(0, size)
     110             :         ZEND_ARG_INFO(1, response)
     111             : ZEND_END_ARG_INFO()
     112             : 
     113             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_nlist, 0)
     114             :         ZEND_ARG_INFO(0, ftp)
     115             :         ZEND_ARG_INFO(0, directory)
     116             : ZEND_END_ARG_INFO()
     117             : 
     118             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_rawlist, 0, 0, 2)
     119             :         ZEND_ARG_INFO(0, ftp)
     120             :         ZEND_ARG_INFO(0, directory)
     121             :         ZEND_ARG_INFO(0, recursive)
     122             : ZEND_END_ARG_INFO()
     123             : 
     124             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_systype, 0)
     125             :         ZEND_ARG_INFO(0, ftp)
     126             : ZEND_END_ARG_INFO()
     127             : 
     128             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fget, 0, 0, 4)
     129             :         ZEND_ARG_INFO(0, ftp)
     130             :         ZEND_ARG_INFO(0, fp)
     131             :         ZEND_ARG_INFO(0, remote_file)
     132             :         ZEND_ARG_INFO(0, mode)
     133             :         ZEND_ARG_INFO(0, resumepos)
     134             : ZEND_END_ARG_INFO()
     135             : 
     136             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fget, 0, 0, 4)
     137             :         ZEND_ARG_INFO(0, ftp)
     138             :         ZEND_ARG_INFO(0, fp)
     139             :         ZEND_ARG_INFO(0, remote_file)
     140             :         ZEND_ARG_INFO(0, mode)
     141             :         ZEND_ARG_INFO(0, resumepos)
     142             : ZEND_END_ARG_INFO()
     143             : 
     144             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_pasv, 0)
     145             :         ZEND_ARG_INFO(0, ftp)
     146             :         ZEND_ARG_INFO(0, pasv)
     147             : ZEND_END_ARG_INFO()
     148             : 
     149             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_get, 0, 0, 4)
     150             :         ZEND_ARG_INFO(0, ftp)
     151             :         ZEND_ARG_INFO(0, local_file)
     152             :         ZEND_ARG_INFO(0, remote_file)
     153             :         ZEND_ARG_INFO(0, mode)
     154             :         ZEND_ARG_INFO(0, resume_pos)
     155             : ZEND_END_ARG_INFO()
     156             : 
     157             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_get, 0, 0, 4)
     158             :         ZEND_ARG_INFO(0, ftp)
     159             :         ZEND_ARG_INFO(0, local_file)
     160             :         ZEND_ARG_INFO(0, remote_file)
     161             :         ZEND_ARG_INFO(0, mode)
     162             :         ZEND_ARG_INFO(0, resume_pos)
     163             : ZEND_END_ARG_INFO()
     164             : 
     165             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_nb_continue, 0)
     166             :         ZEND_ARG_INFO(0, ftp)
     167             : ZEND_END_ARG_INFO()
     168             : 
     169             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fput, 0, 0, 4)
     170             :         ZEND_ARG_INFO(0, ftp)
     171             :         ZEND_ARG_INFO(0, remote_file)
     172             :         ZEND_ARG_INFO(0, fp)
     173             :         ZEND_ARG_INFO(0, mode)
     174             :         ZEND_ARG_INFO(0, startpos)
     175             : ZEND_END_ARG_INFO()
     176             : 
     177             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fput, 0, 0, 4)
     178             :         ZEND_ARG_INFO(0, ftp)
     179             :         ZEND_ARG_INFO(0, remote_file)
     180             :         ZEND_ARG_INFO(0, fp)
     181             :         ZEND_ARG_INFO(0, mode)
     182             :         ZEND_ARG_INFO(0, startpos)
     183             : ZEND_END_ARG_INFO()
     184             : 
     185             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_put, 0, 0, 4)
     186             :         ZEND_ARG_INFO(0, ftp)
     187             :         ZEND_ARG_INFO(0, remote_file)
     188             :         ZEND_ARG_INFO(0, local_file)
     189             :         ZEND_ARG_INFO(0, mode)
     190             :         ZEND_ARG_INFO(0, startpos)
     191             : ZEND_END_ARG_INFO()
     192             : 
     193             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_put, 0, 0, 4)
     194             :         ZEND_ARG_INFO(0, ftp)
     195             :         ZEND_ARG_INFO(0, remote_file)
     196             :         ZEND_ARG_INFO(0, local_file)
     197             :         ZEND_ARG_INFO(0, mode)
     198             :         ZEND_ARG_INFO(0, startpos)
     199             : ZEND_END_ARG_INFO()
     200             : 
     201             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_size, 0)
     202             :         ZEND_ARG_INFO(0, ftp)
     203             :         ZEND_ARG_INFO(0, filename)
     204             : ZEND_END_ARG_INFO()
     205             : 
     206             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_mdtm, 0)
     207             :         ZEND_ARG_INFO(0, ftp)
     208             :         ZEND_ARG_INFO(0, filename)
     209             : ZEND_END_ARG_INFO()
     210             : 
     211             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_rename, 0)
     212             :         ZEND_ARG_INFO(0, ftp)
     213             :         ZEND_ARG_INFO(0, src)
     214             :         ZEND_ARG_INFO(0, dest)
     215             : ZEND_END_ARG_INFO()
     216             : 
     217             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_delete, 0)
     218             :         ZEND_ARG_INFO(0, ftp)
     219             :         ZEND_ARG_INFO(0, file)
     220             : ZEND_END_ARG_INFO()
     221             : 
     222             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_site, 0)
     223             :         ZEND_ARG_INFO(0, ftp)
     224             :         ZEND_ARG_INFO(0, cmd)
     225             : ZEND_END_ARG_INFO()
     226             : 
     227             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_close, 0)
     228             :         ZEND_ARG_INFO(0, ftp)
     229             : ZEND_END_ARG_INFO()
     230             : 
     231             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_set_option, 0)
     232             :         ZEND_ARG_INFO(0, ftp)
     233             :         ZEND_ARG_INFO(0, option)
     234             :         ZEND_ARG_INFO(0, value)
     235             : ZEND_END_ARG_INFO()
     236             : 
     237             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_get_option, 0)
     238             :         ZEND_ARG_INFO(0, ftp)
     239             :         ZEND_ARG_INFO(0, option)
     240             : ZEND_END_ARG_INFO()
     241             : 
     242             : /* }}} */
     243             : 
     244             : const zend_function_entry php_ftp_functions[] = {
     245             :         PHP_FE(ftp_connect,                     arginfo_ftp_connect)
     246             : #if HAVE_OPENSSL_EXT
     247             :         PHP_FE(ftp_ssl_connect,         arginfo_ftp_ssl_connect)
     248             : #endif
     249             :         PHP_FE(ftp_login,                       arginfo_ftp_login)
     250             :         PHP_FE(ftp_pwd,                         arginfo_ftp_pwd)
     251             :         PHP_FE(ftp_cdup,                        arginfo_ftp_cdup)
     252             :         PHP_FE(ftp_chdir,                       arginfo_ftp_chdir)
     253             :         PHP_FE(ftp_exec,                        arginfo_ftp_exec)
     254             :         PHP_FE(ftp_raw,                         arginfo_ftp_raw)
     255             :         PHP_FE(ftp_mkdir,                       arginfo_ftp_mkdir)
     256             :         PHP_FE(ftp_rmdir,                       arginfo_ftp_rmdir)
     257             :         PHP_FE(ftp_chmod,                       arginfo_ftp_chmod)
     258             :         PHP_FE(ftp_alloc,                       arginfo_ftp_alloc)
     259             :         PHP_FE(ftp_nlist,                       arginfo_ftp_nlist)
     260             :         PHP_FE(ftp_rawlist,                     arginfo_ftp_rawlist)
     261             :         PHP_FE(ftp_systype,                     arginfo_ftp_systype)
     262             :         PHP_FE(ftp_pasv,                        arginfo_ftp_pasv)
     263             :         PHP_FE(ftp_get,                         arginfo_ftp_get)
     264             :         PHP_FE(ftp_fget,                        arginfo_ftp_fget)
     265             :         PHP_FE(ftp_put,                         arginfo_ftp_put)
     266             :         PHP_FE(ftp_fput,                        arginfo_ftp_fput)
     267             :         PHP_FE(ftp_size,                        arginfo_ftp_size)
     268             :         PHP_FE(ftp_mdtm,                        arginfo_ftp_mdtm)
     269             :         PHP_FE(ftp_rename,                      arginfo_ftp_rename)
     270             :         PHP_FE(ftp_delete,                      arginfo_ftp_delete)
     271             :         PHP_FE(ftp_site,                        arginfo_ftp_site)
     272             :         PHP_FE(ftp_close,                       arginfo_ftp_close)
     273             :         PHP_FE(ftp_set_option,          arginfo_ftp_set_option)
     274             :         PHP_FE(ftp_get_option,          arginfo_ftp_get_option)
     275             :         PHP_FE(ftp_nb_fget,                     arginfo_ftp_nb_fget)
     276             :         PHP_FE(ftp_nb_get,                      arginfo_ftp_nb_get)
     277             :         PHP_FE(ftp_nb_continue,         arginfo_ftp_nb_continue)
     278             :         PHP_FE(ftp_nb_put,                      arginfo_ftp_nb_put)
     279             :         PHP_FE(ftp_nb_fput,                     arginfo_ftp_nb_fput)
     280             :         PHP_FALIAS(ftp_quit, ftp_close, arginfo_ftp_close)
     281             :         PHP_FE_END
     282             : };
     283             : 
     284             : zend_module_entry php_ftp_module_entry = {
     285             :     STANDARD_MODULE_HEADER,
     286             :         "ftp",
     287             :         php_ftp_functions,
     288             :         PHP_MINIT(ftp),
     289             :         NULL,
     290             :         NULL,
     291             :         NULL,
     292             :         PHP_MINFO(ftp),
     293             :     NO_VERSION_YET,
     294             :         STANDARD_MODULE_PROPERTIES
     295             : };
     296             : 
     297             : #if COMPILE_DL_FTP
     298             : ZEND_GET_MODULE(php_ftp)
     299             : #endif
     300             : 
     301          31 : static void ftp_destructor_ftpbuf(zend_resource *rsrc)
     302             : {
     303          31 :         ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr;
     304             : 
     305          31 :         ftp_close(ftp);
     306          31 : }
     307             : 
     308       20871 : PHP_MINIT_FUNCTION(ftp)
     309             : {
     310       20871 :         le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);
     311       20871 :         REGISTER_LONG_CONSTANT("FTP_ASCII",  FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     312       20871 :         REGISTER_LONG_CONSTANT("FTP_TEXT",   FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     313       20871 :         REGISTER_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     314       20871 :         REGISTER_LONG_CONSTANT("FTP_IMAGE",  FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     315       20871 :         REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
     316       20871 :         REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
     317       20871 :         REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
     318       20871 :         REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);
     319       20871 :         REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);
     320       20871 :         REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);
     321       20871 :         return SUCCESS;
     322             : }
     323             : 
     324         145 : PHP_MINFO_FUNCTION(ftp)
     325             : {
     326         145 :         php_info_print_table_start();
     327         145 :         php_info_print_table_row(2, "FTP support", "enabled");
     328         145 :         php_info_print_table_end();
     329         145 : }
     330             : 
     331             : #define XTYPE(xtype, mode)      { \
     332             :                                                                 if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \
     333             :                                                                         php_error_docref(NULL, E_WARNING, "Mode must be FTP_ASCII or FTP_BINARY"); \
     334             :                                                                         RETURN_FALSE; \
     335             :                                                                 } \
     336             :                                                                 xtype = mode; \
     337             :                                                         }
     338             : 
     339             : 
     340             : /* {{{ proto resource ftp_connect(string host [, int port [, int timeout]])
     341             :    Opens a FTP stream */
     342          32 : PHP_FUNCTION(ftp_connect)
     343             : {
     344             :         ftpbuf_t        *ftp;
     345             :         char            *host;
     346             :         size_t          host_len;
     347          32 :         zend_long               port = 0;
     348          32 :         zend_long               timeout_sec = FTP_DEFAULT_TIMEOUT;
     349             : 
     350          32 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {
     351           1 :                 return;
     352             :         }
     353             : 
     354          31 :         if (timeout_sec <= 0) {
     355           1 :                 php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0");
     356           1 :                 RETURN_FALSE;
     357             :         }
     358             : 
     359             :         /* connect */
     360          30 :         if (!(ftp = ftp_open(host, (short)port, timeout_sec))) {
     361           1 :                 RETURN_FALSE;
     362             :         }
     363             : 
     364             :         /* autoseek for resuming */
     365          29 :         ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
     366             : #if HAVE_OPENSSL_EXT
     367             :         /* disable ssl */
     368          29 :         ftp->use_ssl = 0;
     369             : #endif
     370             : 
     371          29 :         RETURN_RES(zend_register_resource(ftp, le_ftpbuf));
     372             : }
     373             : /* }}} */
     374             : 
     375             : #if HAVE_OPENSSL_EXT
     376             : /* {{{ proto resource ftp_ssl_connect(string host [, int port [, int timeout]])
     377             :    Opens a FTP-SSL stream */
     378           2 : PHP_FUNCTION(ftp_ssl_connect)
     379             : {
     380             :         ftpbuf_t        *ftp;
     381             :         char            *host;
     382             :         size_t          host_len;
     383           2 :         zend_long               port = 0;
     384           2 :         zend_long               timeout_sec = FTP_DEFAULT_TIMEOUT;
     385             : 
     386           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {
     387           0 :                 return;
     388             :         }
     389             : 
     390           2 :         if (timeout_sec <= 0) {
     391           0 :                 php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0");
     392           0 :                 RETURN_FALSE;
     393             :         }
     394             : 
     395             :         /* connect */
     396           2 :         if (!(ftp = ftp_open(host, (short)port, timeout_sec))) {
     397           0 :                 RETURN_FALSE;
     398             :         }
     399             : 
     400             :         /* autoseek for resuming */
     401           2 :         ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
     402             :         /* enable ssl */
     403           2 :         ftp->use_ssl = 1;
     404             : 
     405           2 :         RETURN_RES(zend_register_resource(ftp, le_ftpbuf));
     406             : }
     407             : /* }}} */
     408             : #endif
     409             : 
     410             : /* {{{ proto bool ftp_login(resource stream, string username, string password)
     411             :    Logs into the FTP server */
     412          33 : PHP_FUNCTION(ftp_login)
     413             : {
     414             :         zval            *z_ftp;
     415             :         ftpbuf_t        *ftp;
     416             :         char *user, *pass;
     417             :         size_t user_len, pass_len;
     418             : 
     419          33 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) {
     420           1 :                 return;
     421             :         }
     422             : 
     423          32 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     424           0 :                 RETURN_FALSE;
     425             :         }
     426             : 
     427             :         /* log in */
     428          32 :         if (!ftp_login(ftp, user, pass)) {
     429           2 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     430           2 :                 RETURN_FALSE;
     431             :         }
     432             : 
     433          30 :         RETURN_TRUE;
     434             : }
     435             : /* }}} */
     436             : 
     437             : /* {{{ proto string ftp_pwd(resource stream)
     438             :    Returns the present working directory */
     439           7 : PHP_FUNCTION(ftp_pwd)
     440             : {
     441             :         zval            *z_ftp;
     442             :         ftpbuf_t        *ftp;
     443             :         const char      *pwd;
     444             : 
     445           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) {
     446           1 :                 return;
     447             :         }
     448             : 
     449           6 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     450           0 :                 RETURN_FALSE;
     451             :         }
     452             : 
     453           6 :         if (!(pwd = ftp_pwd(ftp))) {
     454           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     455           1 :                 RETURN_FALSE;
     456             :         }
     457             : 
     458          10 :         RETURN_STRING((char*) pwd);
     459             : }
     460             : /* }}} */
     461             : 
     462             : /* {{{ proto bool ftp_cdup(resource stream)
     463             :    Changes to the parent directory */
     464           3 : PHP_FUNCTION(ftp_cdup)
     465             : {
     466             :         zval            *z_ftp;
     467             :         ftpbuf_t        *ftp;
     468             : 
     469           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) {
     470           1 :                 return;
     471             :         }
     472             : 
     473           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     474           0 :                 RETURN_FALSE;
     475             :         }
     476             : 
     477           2 :         if (!ftp_cdup(ftp)) {
     478           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     479           1 :                 RETURN_FALSE;
     480             :         }
     481             : 
     482           1 :         RETURN_TRUE;
     483             : }
     484             : /* }}} */
     485             : 
     486             : /* {{{ proto bool ftp_chdir(resource stream, string directory)
     487             :    Changes directories */
     488           5 : PHP_FUNCTION(ftp_chdir)
     489             : {
     490             :         zval            *z_ftp;
     491             :         ftpbuf_t        *ftp;
     492             :         char            *dir;
     493             :         size_t                  dir_len;
     494             : 
     495           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     496           1 :                 return;
     497             :         }
     498             : 
     499           4 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     500           0 :                 RETURN_FALSE;
     501             :         }
     502             : 
     503             :         /* change directories */
     504           4 :         if (!ftp_chdir(ftp, dir)) {
     505           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     506           1 :                 RETURN_FALSE;
     507             :         }
     508             : 
     509           3 :         RETURN_TRUE;
     510             : }
     511             : /* }}} */
     512             : 
     513             : /* {{{ proto bool ftp_exec(resource stream, string command)
     514             :    Requests execution of a program on the FTP server */
     515           3 : PHP_FUNCTION(ftp_exec)
     516             : {
     517             :         zval            *z_ftp;
     518             :         ftpbuf_t        *ftp;
     519             :         char            *cmd;
     520             :         size_t                  cmd_len;
     521             : 
     522           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     523           1 :                 return;
     524             :         }
     525             : 
     526           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     527           0 :                 RETURN_FALSE;
     528             :         }
     529             : 
     530             :         /* execute serverside command */
     531           2 :         if (!ftp_exec(ftp, cmd)) {
     532           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     533           1 :                 RETURN_FALSE;
     534             :         }
     535             : 
     536           1 :         RETURN_TRUE;
     537             : }
     538             : /* }}} */
     539             : 
     540             : /* {{{ proto array ftp_raw(resource stream, string command)
     541             :    Sends a literal command to the FTP server */
     542           5 : PHP_FUNCTION(ftp_raw)
     543             : {
     544             :         zval            *z_ftp;
     545             :         ftpbuf_t        *ftp;
     546             :         char            *cmd;
     547             :         size_t                  cmd_len;
     548             : 
     549           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     550           1 :                 return;
     551             :         }
     552             : 
     553           4 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     554           0 :                 RETURN_FALSE;
     555             :         }
     556             : 
     557             :         /* execute arbitrary ftp command */
     558           4 :         ftp_raw(ftp, cmd, return_value);
     559             : }
     560             : /* }}} */
     561             : 
     562             : /* {{{ proto string ftp_mkdir(resource stream, string directory)
     563             :    Creates a directory and returns the absolute path for the new directory or false on error */
     564           4 : PHP_FUNCTION(ftp_mkdir)
     565             : {
     566             :         zval            *z_ftp;
     567             :         ftpbuf_t        *ftp;
     568             :         char            *dir;
     569             :         zend_string *tmp;
     570             :         size_t          dir_len;
     571             : 
     572           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     573           1 :                 return;
     574             :         }
     575             : 
     576           3 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     577           0 :                 RETURN_FALSE;
     578             :         }
     579             : 
     580             :         /* create directorie */
     581           3 :         if (NULL == (tmp = ftp_mkdir(ftp, dir))) {
     582           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     583           1 :                 RETURN_FALSE;
     584             :         }
     585             : 
     586           2 :         RETURN_STR(tmp);
     587             : }
     588             : /* }}} */
     589             : 
     590             : /* {{{ proto bool ftp_rmdir(resource stream, string directory)
     591             :    Removes a directory */
     592           3 : PHP_FUNCTION(ftp_rmdir)
     593             : {
     594             :         zval            *z_ftp;
     595             :         ftpbuf_t        *ftp;
     596             :         char            *dir;
     597             :         size_t          dir_len;
     598             : 
     599           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     600           1 :                 return;
     601             :         }
     602             : 
     603           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     604           0 :                 RETURN_FALSE;
     605             :         }
     606             : 
     607             :         /* remove directorie */
     608           2 :         if (!ftp_rmdir(ftp, dir)) {
     609           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     610           1 :                 RETURN_FALSE;
     611             :         }
     612             : 
     613           1 :         RETURN_TRUE;
     614             : }
     615             : /* }}} */
     616             : 
     617             : /* {{{ proto int ftp_chmod(resource stream, int mode, string filename)
     618             :    Sets permissions on a file */
     619           3 : PHP_FUNCTION(ftp_chmod)
     620             : {
     621             :         zval            *z_ftp;
     622             :         ftpbuf_t        *ftp;
     623             :         char            *filename;
     624             :         size_t          filename_len;
     625             :         zend_long               mode;
     626             : 
     627           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlp", &z_ftp, &mode, &filename, &filename_len) == FAILURE) {
     628           1 :                 RETURN_FALSE;
     629             :         }
     630             : 
     631           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     632           0 :                 RETURN_FALSE;
     633             :         }
     634             : 
     635           2 :         if (!ftp_chmod(ftp, mode, filename, filename_len)) {
     636           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     637           1 :                 RETURN_FALSE;
     638             :         }
     639             : 
     640           1 :         RETURN_LONG(mode);
     641             : }
     642             : /* }}} */
     643             : 
     644             : /* {{{ proto bool ftp_alloc(resource stream, int size[, &response])
     645             :    Attempt to allocate space on the remote FTP server */
     646           4 : PHP_FUNCTION(ftp_alloc)
     647             : {
     648           4 :         zval            *z_ftp, *zresponse = NULL;
     649             :         ftpbuf_t        *ftp;
     650             :         zend_long               size, ret;
     651           4 :         zend_string     *response = NULL;
     652             : 
     653           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z/", &z_ftp, &size, &zresponse) == FAILURE) {
     654           1 :                 RETURN_FALSE;
     655             :         }
     656             : 
     657           3 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     658           0 :                 RETURN_FALSE;
     659             :         }
     660             : 
     661           3 :         ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
     662           3 :         if (response) {
     663           1 :                 zval_dtor(zresponse);
     664           1 :                 ZVAL_STR(zresponse, response);
     665             :         }
     666             : 
     667           3 :         if (!ret) {
     668           1 :                 RETURN_FALSE;
     669             :         }
     670             : 
     671           2 :         RETURN_TRUE;
     672             : }
     673             : /* }}} */
     674             : 
     675             : /* {{{ proto array ftp_nlist(resource stream, string directory)
     676             :    Returns an array of filenames in the given directory */
     677           7 : PHP_FUNCTION(ftp_nlist)
     678             : {
     679             :         zval            *z_ftp;
     680             :         ftpbuf_t        *ftp;
     681             :         char            **nlist, **ptr, *dir;
     682             :         size_t          dir_len;
     683             : 
     684           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &dir, &dir_len) == FAILURE) {
     685           1 :                 return;
     686             :         }
     687             : 
     688           6 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     689           0 :                 RETURN_FALSE;
     690             :         }
     691             : 
     692             :         /* get list of files */
     693           6 :         if (NULL == (nlist = ftp_nlist(ftp, dir))) {
     694           2 :                 RETURN_FALSE;
     695             :         }
     696             : 
     697           4 :         array_init(return_value);
     698          10 :         for (ptr = nlist; *ptr; ptr++) {
     699           6 :                 add_next_index_string(return_value, *ptr);
     700             :         }
     701           4 :         efree(nlist);
     702             : }
     703             : /* }}} */
     704             : 
     705             : /* {{{ proto array ftp_rawlist(resource stream, string directory [, bool recursive])
     706             :    Returns a detailed listing of a directory as an array of output lines */
     707           2 : PHP_FUNCTION(ftp_rawlist)
     708             : {
     709             :         zval            *z_ftp;
     710             :         ftpbuf_t        *ftp;
     711             :         char            **llist, **ptr, *dir;
     712             :         size_t          dir_len;
     713           2 :         zend_bool       recursive = 0;
     714             : 
     715           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|b", &z_ftp, &dir, &dir_len, &recursive) == FAILURE) {
     716           1 :                 return;
     717             :         }
     718             : 
     719           1 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     720           0 :                 RETURN_FALSE;
     721             :         }
     722             : 
     723             :         /* get raw directory listing */
     724           1 :         if (NULL == (llist = ftp_list(ftp, dir, recursive))) {
     725           1 :                 RETURN_FALSE;
     726             :         }
     727             : 
     728           0 :         array_init(return_value);
     729           0 :         for (ptr = llist; *ptr; ptr++) {
     730           0 :                 add_next_index_string(return_value, *ptr);
     731             :         }
     732           0 :         efree(llist);
     733             : }
     734             : /* }}} */
     735             : 
     736             : /* {{{ proto string ftp_systype(resource stream)
     737             :    Returns the system type identifier */
     738           4 : PHP_FUNCTION(ftp_systype)
     739             : {
     740             :         zval            *z_ftp;
     741             :         ftpbuf_t        *ftp;
     742             :         const char      *syst;
     743             : 
     744           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) {
     745           1 :                 return;
     746             :         }
     747             : 
     748           3 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     749           0 :                 RETURN_FALSE;
     750             :         }
     751             : 
     752           3 :         if (NULL == (syst = ftp_syst(ftp))) {
     753           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     754           1 :                 RETURN_FALSE;
     755             :         }
     756             : 
     757           4 :         RETURN_STRING((char*) syst);
     758             : }
     759             : /* }}} */
     760             : 
     761             : /* {{{ proto bool ftp_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     762             :    Retrieves a file from the FTP server and writes it to an open file */
     763           8 : PHP_FUNCTION(ftp_fget)
     764             : {
     765             :         zval            *z_ftp, *z_file;
     766             :         ftpbuf_t        *ftp;
     767             :         ftptype_t       xtype;
     768             :         php_stream      *stream;
     769             :         char            *file;
     770             :         size_t          file_len;
     771           8 :         zend_long               mode, resumepos=0;
     772             : 
     773           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     774           1 :                 return;
     775             :         }
     776             : 
     777           7 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     778           0 :                 RETURN_FALSE;
     779             :         }
     780           7 :         php_stream_from_res(stream, Z_RES_P(z_file));
     781           7 :         XTYPE(xtype, mode);
     782             : 
     783             :         /* ignore autoresume if autoseek is switched off */
     784           6 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     785           1 :                 resumepos = 0;
     786             :         }
     787             : 
     788           6 :         if (ftp->autoseek && resumepos) {
     789             :                 /* if autoresume is wanted seek to end */
     790           2 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     791           1 :                         php_stream_seek(stream, 0, SEEK_END);
     792           1 :                         resumepos = php_stream_tell(stream);
     793             :                 } else {
     794           1 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     795             :                 }
     796             :         }
     797             : 
     798           6 :         if (!ftp_get(ftp, stream, file, xtype, resumepos)) {
     799           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     800           1 :                 RETURN_FALSE;
     801             :         }
     802             : 
     803           5 :         RETURN_TRUE;
     804             : }
     805             : /* }}} */
     806             : 
     807             : /* {{{ proto int ftp_nb_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     808             :    Retrieves a file from the FTP server asynchronly and writes it to an open file */
     809           5 : PHP_FUNCTION(ftp_nb_fget)
     810             : {
     811             :         zval            *z_ftp, *z_file;
     812             :         ftpbuf_t        *ftp;
     813             :         ftptype_t       xtype;
     814             :         php_stream      *stream;
     815             :         char            *file;
     816             :         size_t          file_len;
     817           5 :         zend_long               mode, resumepos=0, ret;
     818             : 
     819           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     820           1 :                 return;
     821             :         }
     822             : 
     823           4 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     824           0 :                 RETURN_FALSE;
     825             :         }
     826           4 :         php_stream_from_res(stream, Z_RES_P(z_file));
     827           4 :         XTYPE(xtype, mode);
     828             : 
     829             :         /* ignore autoresume if autoseek is switched off */
     830           3 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     831           1 :                 resumepos = 0;
     832             :         }
     833             : 
     834           3 :         if (ftp->autoseek && resumepos) {
     835             :                 /* if autoresume is wanted seek to end */
     836           2 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     837           1 :                         php_stream_seek(stream, 0, SEEK_END);
     838           1 :                         resumepos = php_stream_tell(stream);
     839             :                 } else {
     840           1 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     841             :                 }
     842             :         }
     843             : 
     844             :         /* configuration */
     845           3 :         ftp->direction = 0;   /* recv */
     846           3 :         ftp->closestream = 0; /* do not close */
     847             : 
     848           3 :         if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos)) == PHP_FTP_FAILED) {
     849           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     850           0 :                 RETURN_LONG(ret);
     851             :         }
     852             : 
     853           3 :         RETURN_LONG(ret);
     854             : }
     855             : /* }}} */
     856             : 
     857             : /* {{{ proto bool ftp_pasv(resource stream, bool pasv)
     858             :    Turns passive mode on or off */
     859           1 : PHP_FUNCTION(ftp_pasv)
     860             : {
     861             :         zval            *z_ftp;
     862             :         ftpbuf_t        *ftp;
     863             :         zend_bool       pasv;
     864             : 
     865           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &z_ftp, &pasv) == FAILURE) {
     866           1 :                 return;
     867             :         }
     868             : 
     869           0 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     870           0 :                 RETURN_FALSE;
     871             :         }
     872             : 
     873           0 :         if (!ftp_pasv(ftp, pasv ? 1 : 0)) {
     874           0 :                 RETURN_FALSE;
     875             :         }
     876             : 
     877           0 :         RETURN_TRUE;
     878             : }
     879             : /* }}} */
     880             : 
     881             : /* {{{ proto bool ftp_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     882             :    Retrieves a file from the FTP server and writes it to a local file */
     883           5 : PHP_FUNCTION(ftp_get)
     884             : {
     885             :         zval            *z_ftp;
     886             :         ftpbuf_t        *ftp;
     887             :         ftptype_t       xtype;
     888             :         php_stream      *outstream;
     889             :         char            *local, *remote;
     890             :         size_t          local_len, remote_len;
     891           5 :         zend_long               mode, resumepos=0;
     892             : 
     893           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rppl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     894           1 :                 return;
     895             :         }
     896             : 
     897           4 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     898           0 :                 RETURN_FALSE;
     899             :         }
     900           4 :         XTYPE(xtype, mode);
     901             : 
     902             :         /* ignore autoresume if autoseek is switched off */
     903           3 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     904           0 :                 resumepos = 0;
     905             :         }
     906             : 
     907             : #ifdef PHP_WIN32
     908             :         mode = FTPTYPE_IMAGE;
     909             : #endif
     910             : 
     911           3 :         if (ftp->autoseek && resumepos) {
     912           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     913           0 :                 if (outstream == NULL) {
     914           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     915             :                 }
     916           0 :                 if (outstream != NULL) {
     917             :                         /* if autoresume is wanted seek to end */
     918           0 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     919           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     920           0 :                                 resumepos = php_stream_tell(outstream);
     921             :                         } else {
     922           0 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     923             :                         }
     924             :                 }
     925             :         } else {
     926           3 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     927             :         }
     928             : 
     929           3 :         if (outstream == NULL)  {
     930           0 :                 php_error_docref(NULL, E_WARNING, "Error opening %s", local);
     931           0 :                 RETURN_FALSE;
     932             :         }
     933             : 
     934           3 :         if (!ftp_get(ftp, outstream, remote, xtype, resumepos)) {
     935           1 :                 php_stream_close(outstream);
     936           1 :                 VCWD_UNLINK(local);
     937           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
     938           1 :                 RETURN_FALSE;
     939             :         }
     940             : 
     941           2 :         php_stream_close(outstream);
     942           2 :         RETURN_TRUE;
     943             : }
     944             : /* }}} */
     945             : 
     946             : /* {{{ proto int ftp_nb_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     947             :    Retrieves a file from the FTP server nbhronly and writes it to a local file */
     948           3 : PHP_FUNCTION(ftp_nb_get)
     949             : {
     950             :         zval            *z_ftp;
     951             :         ftpbuf_t        *ftp;
     952             :         ftptype_t       xtype;
     953             :         php_stream      *outstream;
     954             :         char            *local, *remote;
     955             :         size_t          local_len, remote_len;
     956             :         int ret;
     957           3 :         zend_long               mode, resumepos=0;
     958             : 
     959           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rssl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     960           1 :                 return;
     961             :         }
     962             : 
     963           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
     964           0 :                 RETURN_FALSE;
     965             :         }
     966           2 :         XTYPE(xtype, mode);
     967             : 
     968             :         /* ignore autoresume if autoseek is switched off */
     969           2 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     970           0 :                 resumepos = 0;
     971             :         }
     972             : #ifdef PHP_WIN32
     973             :         mode = FTPTYPE_IMAGE;
     974             : #endif
     975           3 :         if (ftp->autoseek && resumepos) {
     976           1 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     977           1 :                 if (outstream == NULL) {
     978           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     979             :                 }
     980           1 :                 if (outstream != NULL) {
     981             :                         /* if autoresume is wanted seek to end */
     982           1 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     983           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     984           0 :                                 resumepos = php_stream_tell(outstream);
     985             :                         } else {
     986           1 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     987             :                         }
     988             :                 }
     989             :         } else {
     990           1 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     991             :         }
     992             : 
     993           2 :         if (outstream == NULL)  {
     994           0 :                 php_error_docref(NULL, E_WARNING, "Error opening %s", local);
     995           0 :                 RETURN_FALSE;
     996             :         }
     997             : 
     998             :         /* configuration */
     999           2 :         ftp->direction = 0;   /* recv */
    1000           2 :         ftp->closestream = 1; /* do close */
    1001             : 
    1002           2 :         if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos)) == PHP_FTP_FAILED) {
    1003           0 :                 php_stream_close(outstream);
    1004           0 :                 ftp->stream = NULL;
    1005           0 :                 VCWD_UNLINK(local);
    1006           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1007           0 :                 RETURN_LONG(PHP_FTP_FAILED);
    1008             :         }
    1009             : 
    1010           2 :         if (ret == PHP_FTP_FINISHED){
    1011           0 :                 php_stream_close(outstream);
    1012           0 :                 ftp->stream = NULL;
    1013             :         }
    1014             : 
    1015           2 :         RETURN_LONG(ret);
    1016             : }
    1017             : /* }}} */
    1018             : 
    1019             : /* {{{ proto int ftp_nb_continue(resource stream)
    1020             :    Continues retrieving/sending a file nbronously */
    1021           7 : PHP_FUNCTION(ftp_nb_continue)
    1022             : {
    1023             :         zval            *z_ftp;
    1024             :         ftpbuf_t        *ftp;
    1025             :         zend_long               ret;
    1026             : 
    1027           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) {
    1028           1 :                 return;
    1029             :         }
    1030             : 
    1031           6 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1032           0 :                 RETURN_FALSE;
    1033             :         }
    1034             : 
    1035           6 :         if (!ftp->nb) {
    1036           1 :                 php_error_docref(NULL, E_WARNING, "no nbronous transfer to continue.");
    1037           1 :                 RETURN_LONG(PHP_FTP_FAILED);
    1038             :         }
    1039             : 
    1040           5 :         if (ftp->direction) {
    1041           0 :                 ret=ftp_nb_continue_write(ftp);
    1042             :         } else {
    1043           5 :                 ret=ftp_nb_continue_read(ftp);
    1044             :         }
    1045             : 
    1046           5 :         if (ret != PHP_FTP_MOREDATA && ftp->closestream) {
    1047           1 :                 php_stream_close(ftp->stream);
    1048           1 :                 ftp->stream = NULL;
    1049             :         }
    1050             : 
    1051           5 :         if (ret == PHP_FTP_FAILED) {
    1052           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1053             :         }
    1054             : 
    1055           5 :         RETURN_LONG(ret);
    1056             : }
    1057             : /* }}} */
    1058             : 
    1059             : /* {{{ proto bool ftp_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1060             :    Stores a file from an open file to the FTP server */
    1061           2 : PHP_FUNCTION(ftp_fput)
    1062             : {
    1063             :         zval            *z_ftp, *z_file;
    1064             :         ftpbuf_t        *ftp;
    1065             :         ftptype_t       xtype;
    1066             :         size_t          remote_len;
    1067           2 :         zend_long               mode, startpos=0;
    1068             :         php_stream      *stream;
    1069             :         char            *remote;
    1070             : 
    1071           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1072           1 :                 return;
    1073             :         }
    1074             : 
    1075           1 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1076           0 :                 RETURN_FALSE;
    1077             :         }
    1078           1 :         php_stream_from_zval(stream, z_file);
    1079           1 :         XTYPE(xtype, mode);
    1080             : 
    1081             :         /* ignore autoresume if autoseek is switched off */
    1082           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1083           0 :                 startpos = 0;
    1084             :         }
    1085             : 
    1086           0 :         if (ftp->autoseek && startpos) {
    1087             :                 /* if autoresume is wanted ask for remote size */
    1088           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1089           0 :                         startpos = ftp_size(ftp, remote);
    1090           0 :                         if (startpos < 0) {
    1091           0 :                                 startpos = 0;
    1092             :                         }
    1093             :                 }
    1094           0 :                 if (startpos) {
    1095           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1096             :                 }
    1097             :         }
    1098             : 
    1099           0 :         if (!ftp_put(ftp, remote, stream, xtype, startpos)) {
    1100           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1101           0 :                 RETURN_FALSE;
    1102             :         }
    1103             : 
    1104           0 :         RETURN_TRUE;
    1105             : }
    1106             : /* }}} */
    1107             : 
    1108             : /* {{{ proto int ftp_nb_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1109             :    Stores a file from an open file to the FTP server nbronly */
    1110           2 : PHP_FUNCTION(ftp_nb_fput)
    1111             : {
    1112             :         zval            *z_ftp, *z_file;
    1113             :         ftpbuf_t        *ftp;
    1114             :         ftptype_t       xtype;
    1115             :         size_t          remote_len;
    1116             :         int             ret;
    1117           2 :         zend_long       mode, startpos=0;
    1118             :         php_stream      *stream;
    1119             :         char            *remote;
    1120             : 
    1121           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1122           1 :                 return;
    1123             :         }
    1124             : 
    1125           1 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1126           0 :                 RETURN_FALSE;
    1127             :         }
    1128           1 :         php_stream_from_res(stream, Z_RES_P(z_file));
    1129           1 :         XTYPE(xtype, mode);
    1130             : 
    1131             :         /* ignore autoresume if autoseek is switched off */
    1132           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1133           0 :                 startpos = 0;
    1134             :         }
    1135             : 
    1136           0 :         if (ftp->autoseek && startpos) {
    1137             :                 /* if autoresume is wanted ask for remote size */
    1138           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1139           0 :                         startpos = ftp_size(ftp, remote);
    1140           0 :                         if (startpos < 0) {
    1141           0 :                                 startpos = 0;
    1142             :                         }
    1143             :                 }
    1144           0 :                 if (startpos) {
    1145           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1146             :                 }
    1147             :         }
    1148             : 
    1149             :         /* configuration */
    1150           0 :         ftp->direction = 1;   /* send */
    1151           0 :         ftp->closestream = 0; /* do not close */
    1152             : 
    1153           0 :         if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos)) == PHP_FTP_FAILED)) {
    1154           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1155           0 :                 RETURN_LONG(ret);
    1156             :         }
    1157             : 
    1158           0 :         RETURN_LONG(ret);
    1159             : }
    1160             : /* }}} */
    1161             : 
    1162             : 
    1163             : /* {{{ proto bool ftp_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1164             :    Stores a file on the FTP server */
    1165           3 : PHP_FUNCTION(ftp_put)
    1166             : {
    1167             :         zval            *z_ftp;
    1168             :         ftpbuf_t        *ftp;
    1169             :         ftptype_t       xtype;
    1170             :         char            *remote, *local;
    1171             :         size_t          remote_len, local_len;
    1172           3 :         zend_long               mode, startpos=0;
    1173             :         php_stream      *instream;
    1174             : 
    1175           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1176           1 :                 return;
    1177             :         }
    1178             : 
    1179           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1180           0 :                 RETURN_FALSE;
    1181             :         }
    1182           2 :         XTYPE(xtype, mode);
    1183             : 
    1184           2 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1185           0 :                 RETURN_FALSE;
    1186             :         }
    1187             : 
    1188             :         /* ignore autoresume if autoseek is switched off */
    1189           2 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1190           0 :                 startpos = 0;
    1191             :         }
    1192             : 
    1193           2 :         if (ftp->autoseek && startpos) {
    1194             :                 /* if autoresume is wanted ask for remote size */
    1195           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1196           0 :                         startpos = ftp_size(ftp, remote);
    1197           0 :                         if (startpos < 0) {
    1198           0 :                                 startpos = 0;
    1199             :                         }
    1200             :                 }
    1201           0 :                 if (startpos) {
    1202           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1203             :                 }
    1204             :         }
    1205             : 
    1206           2 :         if (!ftp_put(ftp, remote, instream, xtype, startpos)) {
    1207           0 :                 php_stream_close(instream);
    1208           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1209           0 :                 RETURN_FALSE;
    1210             :         }
    1211           2 :         php_stream_close(instream);
    1212             : 
    1213           2 :         RETURN_TRUE;
    1214             : }
    1215             : /* }}} */
    1216             : 
    1217             : 
    1218             : /* {{{ proto int ftp_nb_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1219             :    Stores a file on the FTP server */
    1220           1 : PHP_FUNCTION(ftp_nb_put)
    1221             : {
    1222             :         zval            *z_ftp;
    1223             :         ftpbuf_t        *ftp;
    1224             :         ftptype_t       xtype;
    1225             :         char            *remote, *local;
    1226             :         size_t          remote_len, local_len;
    1227           1 :         zend_long               mode, startpos=0, ret;
    1228             :         php_stream      *instream;
    1229             : 
    1230           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1231           1 :                 return;
    1232             :         }
    1233             : 
    1234           0 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1235           0 :                 RETURN_FALSE;
    1236             :         }
    1237           0 :         XTYPE(xtype, mode);
    1238             : 
    1239           0 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1240           0 :                 RETURN_FALSE;
    1241             :         }
    1242             : 
    1243             :         /* ignore autoresume if autoseek is switched off */
    1244           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1245           0 :                 startpos = 0;
    1246             :         }
    1247             : 
    1248           0 :         if (ftp->autoseek && startpos) {
    1249             :                 /* if autoresume is wanted ask for remote size */
    1250           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1251           0 :                         startpos = ftp_size(ftp, remote);
    1252           0 :                         if (startpos < 0) {
    1253           0 :                                 startpos = 0;
    1254             :                         }
    1255             :                 }
    1256           0 :                 if (startpos) {
    1257           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1258             :                 }
    1259             :         }
    1260             : 
    1261             :         /* configuration */
    1262           0 :         ftp->direction = 1;   /* send */
    1263           0 :         ftp->closestream = 1; /* do close */
    1264             : 
    1265           0 :         ret = ftp_nb_put(ftp, remote, instream, xtype, startpos);
    1266             : 
    1267           0 :         if (ret != PHP_FTP_MOREDATA) {
    1268           0 :                 php_stream_close(instream);
    1269           0 :                 ftp->stream = NULL;
    1270             :         }
    1271             : 
    1272           0 :         if (ret == PHP_FTP_FAILED) {
    1273           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1274             :         }
    1275             : 
    1276           0 :         RETURN_LONG(ret);
    1277             : }
    1278             : /* }}} */
    1279             : 
    1280             : /* {{{ proto int ftp_size(resource stream, string filename)
    1281             :    Returns the size of the file, or -1 on error */
    1282           3 : PHP_FUNCTION(ftp_size)
    1283             : {
    1284             :         zval            *z_ftp;
    1285             :         ftpbuf_t        *ftp;
    1286             :         char            *file;
    1287             :         size_t          file_len;
    1288             : 
    1289           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1290           1 :                 return;
    1291             :         }
    1292             : 
    1293           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1294           0 :                 RETURN_FALSE;
    1295             :         }
    1296             : 
    1297             :         /* get file size */
    1298           2 :         RETURN_LONG(ftp_size(ftp, file));
    1299             : }
    1300             : /* }}} */
    1301             : 
    1302             : /* {{{ proto int ftp_mdtm(resource stream, string filename)
    1303             :    Returns the last modification time of the file, or -1 on error */
    1304           8 : PHP_FUNCTION(ftp_mdtm)
    1305             : {
    1306             :         zval            *z_ftp;
    1307             :         ftpbuf_t        *ftp;
    1308             :         char            *file;
    1309             :         size_t          file_len;
    1310             : 
    1311           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1312           1 :                 return;
    1313             :         }
    1314             : 
    1315           7 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1316           0 :                 RETURN_FALSE;
    1317             :         }
    1318             : 
    1319             :         /* get file mod time */
    1320           7 :         RETURN_LONG(ftp_mdtm(ftp, file));
    1321             : }
    1322             : /* }}} */
    1323             : 
    1324             : /* {{{ proto bool ftp_rename(resource stream, string src, string dest)
    1325             :    Renames the given file to a new path */
    1326           1 : PHP_FUNCTION(ftp_rename)
    1327             : {
    1328             :         zval            *z_ftp;
    1329             :         ftpbuf_t        *ftp;
    1330             :         char            *src, *dest;
    1331             :         size_t          src_len, dest_len;
    1332             : 
    1333           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &z_ftp, &src, &src_len, &dest, &dest_len) == FAILURE) {
    1334           1 :                 return;
    1335             :         }
    1336             : 
    1337           0 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1338           0 :                 RETURN_FALSE;
    1339             :         }
    1340             : 
    1341             :         /* rename the file */
    1342           0 :         if (!ftp_rename(ftp, src, dest)) {
    1343           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1344           0 :                 RETURN_FALSE;
    1345             :         }
    1346             : 
    1347           0 :         RETURN_TRUE;
    1348             : }
    1349             : /* }}} */
    1350             : 
    1351             : /* {{{ proto bool ftp_delete(resource stream, string file)
    1352             :    Deletes a file */
    1353           2 : PHP_FUNCTION(ftp_delete)
    1354             : {
    1355             :         zval            *z_ftp;
    1356             :         ftpbuf_t        *ftp;
    1357             :         char            *file;
    1358             :         size_t          file_len;
    1359             : 
    1360           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &file, &file_len) == FAILURE) {
    1361           1 :                 return;
    1362             :         }
    1363             : 
    1364           1 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1365           0 :                 RETURN_FALSE;
    1366             :         }
    1367             : 
    1368             :         /* delete the file */
    1369           1 :         if (!ftp_delete(ftp, file)) {
    1370           1 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1371           1 :                 RETURN_FALSE;
    1372             :         }
    1373             : 
    1374           0 :         RETURN_TRUE;
    1375             : }
    1376             : /* }}} */
    1377             : 
    1378             : /* {{{ proto bool ftp_site(resource stream, string cmd)
    1379             :    Sends a SITE command to the server */
    1380           1 : PHP_FUNCTION(ftp_site)
    1381             : {
    1382             :         zval            *z_ftp;
    1383             :         ftpbuf_t        *ftp;
    1384             :         char            *cmd;
    1385             :         size_t          cmd_len;
    1386             : 
    1387           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
    1388           1 :                 return;
    1389             :         }
    1390             : 
    1391           0 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1392           0 :                 RETURN_FALSE;
    1393             :         }
    1394             : 
    1395             :         /* send the site command */
    1396           0 :         if (!ftp_site(ftp, cmd)) {
    1397           0 :                 php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf);
    1398           0 :                 RETURN_FALSE;
    1399             :         }
    1400             : 
    1401           0 :         RETURN_TRUE;
    1402             : }
    1403             : /* }}} */
    1404             : 
    1405             : /* {{{ proto bool ftp_close(resource stream)
    1406             :    Closes the FTP stream */
    1407          12 : PHP_FUNCTION(ftp_close)
    1408             : {
    1409             :         zval            *z_ftp;
    1410             :         ftpbuf_t        *ftp;
    1411             : 
    1412          12 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) {
    1413           1 :                 return;
    1414             :         }
    1415             : 
    1416          11 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1417           0 :                 RETURN_FALSE;
    1418             :         }
    1419             : 
    1420          11 :         ftp_quit(ftp);
    1421             : 
    1422          11 :         RETURN_BOOL(zend_list_close(Z_RES_P(z_ftp)) == SUCCESS);
    1423             : }
    1424             : /* }}} */
    1425             : 
    1426             : /* {{{ proto bool ftp_set_option(resource stream, int option, mixed value)
    1427             :    Sets an FTP option */
    1428           3 : PHP_FUNCTION(ftp_set_option)
    1429             : {
    1430             :         zval            *z_ftp, *z_value;
    1431             :         zend_long               option;
    1432             :         ftpbuf_t        *ftp;
    1433             : 
    1434           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &z_ftp, &option, &z_value) == FAILURE) {
    1435           1 :                 return;
    1436             :         }
    1437             : 
    1438           2 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1439           0 :                 RETURN_FALSE;
    1440             :         }
    1441             : 
    1442           2 :         switch (option) {
    1443             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1444           0 :                         if (Z_TYPE_P(z_value) != IS_LONG) {
    1445           0 :                                 php_error_docref(NULL, E_WARNING, "Option TIMEOUT_SEC expects value of type long, %s given",
    1446             :                                         zend_zval_type_name(z_value));
    1447           0 :                                 RETURN_FALSE;
    1448             :                         }
    1449           0 :                         if (Z_LVAL_P(z_value) <= 0) {
    1450           0 :                                 php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0");
    1451           0 :                                 RETURN_FALSE;
    1452             :                         }
    1453           0 :                         ftp->timeout_sec = Z_LVAL_P(z_value);
    1454           0 :                         RETURN_TRUE;
    1455             :                         break;
    1456             :                 case PHP_FTP_OPT_AUTOSEEK:
    1457           6 :                         if (Z_TYPE_P(z_value) != IS_TRUE && Z_TYPE_P(z_value) != IS_FALSE) {
    1458           0 :                                 php_error_docref(NULL, E_WARNING, "Option AUTOSEEK expects value of type boolean, %s given",
    1459             :                                         zend_zval_type_name(z_value));
    1460           0 :                                 RETURN_FALSE;
    1461             :                         }
    1462           4 :                         ftp->autoseek = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0;
    1463           2 :                         RETURN_TRUE;
    1464             :                         break;
    1465             :                 default:
    1466           0 :                         php_error_docref(NULL, E_WARNING, "Unknown option '%pd'", option);
    1467           0 :                         RETURN_FALSE;
    1468             :                         break;
    1469             :         }
    1470             : }
    1471             : /* }}} */
    1472             : 
    1473             : /* {{{ proto mixed ftp_get_option(resource stream, int option)
    1474             :    Gets an FTP option */
    1475           1 : PHP_FUNCTION(ftp_get_option)
    1476             : {
    1477             :         zval            *z_ftp;
    1478             :         zend_long               option;
    1479             :         ftpbuf_t        *ftp;
    1480             : 
    1481           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &z_ftp, &option) == FAILURE) {
    1482           1 :                 return;
    1483             :         }
    1484             : 
    1485           0 :         if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) {
    1486           0 :                 RETURN_FALSE;
    1487             :         }
    1488             : 
    1489           0 :         switch (option) {
    1490             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1491           0 :                         RETURN_LONG(ftp->timeout_sec);
    1492             :                         break;
    1493             :                 case PHP_FTP_OPT_AUTOSEEK:
    1494           0 :                         RETURN_BOOL(ftp->autoseek);
    1495             :                         break;
    1496             :                 default:
    1497           0 :                         php_error_docref(NULL, E_WARNING, "Unknown option '%pd'", option);
    1498           0 :                         RETURN_FALSE;
    1499             :                         break;
    1500             :         }
    1501             : }
    1502             : /* }}} */
    1503             : 
    1504             : #endif /* HAVE_FTP */
    1505             : 
    1506             : /*
    1507             :  * Local variables:
    1508             :  * tab-width: 4
    1509             :  * c-basic-offset: 4
    1510             :  * indent-tabs-mode: t
    1511             :  * End:
    1512             :  */

Generated by: LCOV version 1.10

Generated at Sun, 01 Mar 2015 23:22:25 +0000 (3 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.