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 441 70.5 %
Date: 2014-11-22 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-2014 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 TSRMLS_DC)
     302             : {
     303          31 :         ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr;
     304             : 
     305          31 :         ftp_close(ftp);
     306          31 : }
     307             : 
     308       20507 : PHP_MINIT_FUNCTION(ftp)
     309             : {
     310       20507 :         le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);
     311       20507 :         REGISTER_LONG_CONSTANT("FTP_ASCII",  FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     312       20507 :         REGISTER_LONG_CONSTANT("FTP_TEXT",   FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     313       20507 :         REGISTER_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     314       20507 :         REGISTER_LONG_CONSTANT("FTP_IMAGE",  FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     315       20507 :         REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
     316       20507 :         REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
     317       20507 :         REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
     318       20507 :         REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);
     319       20507 :         REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);
     320       20507 :         REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);
     321       20507 :         return SUCCESS;
     322             : }
     323             : 
     324         143 : PHP_MINFO_FUNCTION(ftp)
     325             : {
     326         143 :         php_info_print_table_start();
     327         143 :         php_info_print_table_row(2, "FTP support", "enabled");
     328         143 :         php_info_print_table_end();
     329         143 : }
     330             : 
     331             : #define XTYPE(xtype, mode)      { \
     332             :                                                                 if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \
     333             :                                                                         php_error_docref(NULL TSRMLS_CC, 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() TSRMLS_CC, "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 TSRMLS_CC, 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 TSRMLS_CC))) {
     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 :         ZEND_REGISTER_RESOURCE(return_value, 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() TSRMLS_CC, "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 TSRMLS_CC, 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 TSRMLS_CC))) {
     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 :         ZEND_REGISTER_RESOURCE(return_value, 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() TSRMLS_CC, "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) {
     420           1 :                 return;
     421             :         }
     422             : 
     423          32 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     424             : 
     425             :         /* log in */
     426          32 :         if (!ftp_login(ftp, user, pass TSRMLS_CC)) {
     427           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     428           2 :                 RETURN_FALSE;
     429             :         }
     430             : 
     431          30 :         RETURN_TRUE;
     432             : }
     433             : /* }}} */
     434             : 
     435             : /* {{{ proto string ftp_pwd(resource stream)
     436             :    Returns the present working directory */
     437           7 : PHP_FUNCTION(ftp_pwd)
     438             : {
     439             :         zval            *z_ftp;
     440             :         ftpbuf_t        *ftp;
     441             :         const char      *pwd;
     442             : 
     443           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     444           1 :                 return;
     445             :         }
     446             : 
     447           6 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     448             : 
     449           6 :         if (!(pwd = ftp_pwd(ftp))) {
     450           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     451           1 :                 RETURN_FALSE;
     452             :         }
     453             : 
     454          10 :         RETURN_STRING((char*) pwd);
     455             : }
     456             : /* }}} */
     457             : 
     458             : /* {{{ proto bool ftp_cdup(resource stream)
     459             :    Changes to the parent directory */
     460           3 : PHP_FUNCTION(ftp_cdup)
     461             : {
     462             :         zval            *z_ftp;
     463             :         ftpbuf_t        *ftp;
     464             : 
     465           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     466           1 :                 return;
     467             :         }
     468             : 
     469           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     470             : 
     471           2 :         if (!ftp_cdup(ftp)) {
     472           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     473           1 :                 RETURN_FALSE;
     474             :         }
     475             : 
     476           1 :         RETURN_TRUE;
     477             : }
     478             : /* }}} */
     479             : 
     480             : /* {{{ proto bool ftp_chdir(resource stream, string directory)
     481             :    Changes directories */
     482           5 : PHP_FUNCTION(ftp_chdir)
     483             : {
     484             :         zval            *z_ftp;
     485             :         ftpbuf_t        *ftp;
     486             :         char            *dir;
     487             :         size_t                  dir_len;
     488             : 
     489           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     490           1 :                 return;
     491             :         }
     492             : 
     493           4 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     494             : 
     495             :         /* change directories */
     496           4 :         if (!ftp_chdir(ftp, dir)) {
     497           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     498           1 :                 RETURN_FALSE;
     499             :         }
     500             : 
     501           3 :         RETURN_TRUE;
     502             : }
     503             : /* }}} */
     504             : 
     505             : /* {{{ proto bool ftp_exec(resource stream, string command)
     506             :    Requests execution of a program on the FTP server */
     507           3 : PHP_FUNCTION(ftp_exec)
     508             : {
     509             :         zval            *z_ftp;
     510             :         ftpbuf_t        *ftp;
     511             :         char            *cmd;
     512             :         size_t                  cmd_len;
     513             : 
     514           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     515           1 :                 return;
     516             :         }
     517             : 
     518           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     519             : 
     520             :         /* execute serverside command */
     521           2 :         if (!ftp_exec(ftp, cmd)) {
     522           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     523           1 :                 RETURN_FALSE;
     524             :         }
     525             : 
     526           1 :         RETURN_TRUE;
     527             : }
     528             : /* }}} */
     529             : 
     530             : /* {{{ proto array ftp_raw(resource stream, string command)
     531             :    Sends a literal command to the FTP server */
     532           5 : PHP_FUNCTION(ftp_raw)
     533             : {
     534             :         zval            *z_ftp;
     535             :         ftpbuf_t        *ftp;
     536             :         char            *cmd;
     537             :         size_t                  cmd_len;
     538             : 
     539           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     540           1 :                 return;
     541             :         }
     542             : 
     543           4 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     544             : 
     545             :         /* execute arbitrary ftp command */
     546           4 :         ftp_raw(ftp, cmd, return_value);
     547             : }
     548             : /* }}} */
     549             : 
     550             : /* {{{ proto string ftp_mkdir(resource stream, string directory)
     551             :    Creates a directory and returns the absolute path for the new directory or false on error */
     552           4 : PHP_FUNCTION(ftp_mkdir)
     553             : {
     554             :         zval            *z_ftp;
     555             :         ftpbuf_t        *ftp;
     556             :         char            *dir;
     557             :         zend_string *tmp;
     558             :         size_t          dir_len;
     559             : 
     560           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     561           1 :                 return;
     562             :         }
     563             : 
     564           3 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     565             : 
     566             :         /* create directorie */
     567           3 :         if (NULL == (tmp = ftp_mkdir(ftp, dir))) {
     568           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     569           1 :                 RETURN_FALSE;
     570             :         }
     571             : 
     572           2 :         RETURN_STR(tmp);
     573             : }
     574             : /* }}} */
     575             : 
     576             : /* {{{ proto bool ftp_rmdir(resource stream, string directory)
     577             :    Removes a directory */
     578           3 : PHP_FUNCTION(ftp_rmdir)
     579             : {
     580             :         zval            *z_ftp;
     581             :         ftpbuf_t        *ftp;
     582             :         char            *dir;
     583             :         size_t          dir_len;
     584             : 
     585           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     586           1 :                 return;
     587             :         }
     588             : 
     589           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     590             : 
     591             :         /* remove directorie */
     592           2 :         if (!ftp_rmdir(ftp, dir)) {
     593           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     594           1 :                 RETURN_FALSE;
     595             :         }
     596             : 
     597           1 :         RETURN_TRUE;
     598             : }
     599             : /* }}} */
     600             : 
     601             : /* {{{ proto int ftp_chmod(resource stream, int mode, string filename)
     602             :    Sets permissions on a file */
     603           3 : PHP_FUNCTION(ftp_chmod)
     604             : {
     605             :         zval            *z_ftp;
     606             :         ftpbuf_t        *ftp;
     607             :         char            *filename;
     608             :         size_t          filename_len;
     609             :         zend_long               mode;
     610             : 
     611           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlp", &z_ftp, &mode, &filename, &filename_len) == FAILURE) {
     612           1 :                 RETURN_FALSE;
     613             :         }
     614             : 
     615           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     616             : 
     617           2 :         if (!ftp_chmod(ftp, mode, filename, filename_len)) {
     618           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     619           1 :                 RETURN_FALSE;
     620             :         }
     621             : 
     622           1 :         RETURN_LONG(mode);
     623             : }
     624             : /* }}} */
     625             : 
     626             : /* {{{ proto bool ftp_alloc(resource stream, int size[, &response])
     627             :    Attempt to allocate space on the remote FTP server */
     628           4 : PHP_FUNCTION(ftp_alloc)
     629             : {
     630           4 :         zval            *z_ftp, *zresponse = NULL;
     631             :         ftpbuf_t        *ftp;
     632             :         zend_long               size, ret;
     633           4 :         zend_string     *response = NULL;
     634             : 
     635           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &z_ftp, &size, &zresponse) == FAILURE) {
     636           1 :                 RETURN_FALSE;
     637             :         }
     638             : 
     639           3 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     640             : 
     641           3 :         ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
     642           3 :         if (response) {
     643           1 :                 zval_dtor(zresponse);
     644           1 :                 ZVAL_STR(zresponse, response);
     645             :         }
     646             : 
     647           3 :         if (!ret) {
     648           1 :                 RETURN_FALSE;
     649             :         }
     650             : 
     651           2 :         RETURN_TRUE;
     652             : }
     653             : /* }}} */
     654             : 
     655             : /* {{{ proto array ftp_nlist(resource stream, string directory)
     656             :    Returns an array of filenames in the given directory */
     657           7 : PHP_FUNCTION(ftp_nlist)
     658             : {
     659             :         zval            *z_ftp;
     660             :         ftpbuf_t        *ftp;
     661             :         char            **nlist, **ptr, *dir;
     662             :         size_t          dir_len;
     663             : 
     664           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &dir, &dir_len) == FAILURE) {
     665           1 :                 return;
     666             :         }
     667             : 
     668           6 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     669             : 
     670             :         /* get list of files */
     671           6 :         if (NULL == (nlist = ftp_nlist(ftp, dir TSRMLS_CC))) {
     672           2 :                 RETURN_FALSE;
     673             :         }
     674             : 
     675           4 :         array_init(return_value);
     676          10 :         for (ptr = nlist; *ptr; ptr++) {
     677           6 :                 add_next_index_string(return_value, *ptr);
     678             :         }
     679           4 :         efree(nlist);
     680             : }
     681             : /* }}} */
     682             : 
     683             : /* {{{ proto array ftp_rawlist(resource stream, string directory [, bool recursive])
     684             :    Returns a detailed listing of a directory as an array of output lines */
     685           2 : PHP_FUNCTION(ftp_rawlist)
     686             : {
     687             :         zval            *z_ftp;
     688             :         ftpbuf_t        *ftp;
     689             :         char            **llist, **ptr, *dir;
     690             :         size_t          dir_len;
     691           2 :         zend_bool       recursive = 0;
     692             : 
     693           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &z_ftp, &dir, &dir_len, &recursive) == FAILURE) {
     694           1 :                 return;
     695             :         }
     696             : 
     697           1 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     698             : 
     699             :         /* get raw directory listing */
     700           1 :         if (NULL == (llist = ftp_list(ftp, dir, recursive TSRMLS_CC))) {
     701           1 :                 RETURN_FALSE;
     702             :         }
     703             : 
     704           0 :         array_init(return_value);
     705           0 :         for (ptr = llist; *ptr; ptr++) {
     706           0 :                 add_next_index_string(return_value, *ptr);
     707             :         }
     708           0 :         efree(llist);
     709             : }
     710             : /* }}} */
     711             : 
     712             : /* {{{ proto string ftp_systype(resource stream)
     713             :    Returns the system type identifier */
     714           4 : PHP_FUNCTION(ftp_systype)
     715             : {
     716             :         zval            *z_ftp;
     717             :         ftpbuf_t        *ftp;
     718             :         const char      *syst;
     719             : 
     720           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     721           1 :                 return;
     722             :         }
     723             : 
     724           3 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     725             : 
     726           3 :         if (NULL == (syst = ftp_syst(ftp))) {
     727           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     728           1 :                 RETURN_FALSE;
     729             :         }
     730             : 
     731           4 :         RETURN_STRING((char*) syst);
     732             : }
     733             : /* }}} */
     734             : 
     735             : /* {{{ proto bool ftp_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     736             :    Retrieves a file from the FTP server and writes it to an open file */
     737           8 : PHP_FUNCTION(ftp_fget)
     738             : {
     739             :         zval            *z_ftp, *z_file;
     740             :         ftpbuf_t        *ftp;
     741             :         ftptype_t       xtype;
     742             :         php_stream      *stream;
     743             :         char            *file;
     744             :         size_t          file_len;
     745           8 :         zend_long               mode, resumepos=0;
     746             : 
     747           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     748           1 :                 return;
     749             :         }
     750             : 
     751           7 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     752           7 :         php_stream_from_zval(stream, z_file);
     753           7 :         XTYPE(xtype, mode);
     754             : 
     755             :         /* ignore autoresume if autoseek is switched off */
     756           6 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     757           1 :                 resumepos = 0;
     758             :         }
     759             : 
     760           6 :         if (ftp->autoseek && resumepos) {
     761             :                 /* if autoresume is wanted seek to end */
     762           2 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     763           1 :                         php_stream_seek(stream, 0, SEEK_END);
     764           1 :                         resumepos = php_stream_tell(stream);
     765             :                 } else {
     766           1 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     767             :                 }
     768             :         }
     769             : 
     770           6 :         if (!ftp_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) {
     771           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     772           1 :                 RETURN_FALSE;
     773             :         }
     774             : 
     775           5 :         RETURN_TRUE;
     776             : }
     777             : /* }}} */
     778             : 
     779             : /* {{{ proto int ftp_nb_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     780             :    Retrieves a file from the FTP server asynchronly and writes it to an open file */
     781           5 : PHP_FUNCTION(ftp_nb_fget)
     782             : {
     783             :         zval            *z_ftp, *z_file;
     784             :         ftpbuf_t        *ftp;
     785             :         ftptype_t       xtype;
     786             :         php_stream      *stream;
     787             :         char            *file;
     788             :         size_t          file_len;
     789           5 :         zend_long               mode, resumepos=0, ret;
     790             : 
     791           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     792           1 :                 return;
     793             :         }
     794             : 
     795           4 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     796           4 :         php_stream_from_zval(stream, z_file);
     797           4 :         XTYPE(xtype, mode);
     798             : 
     799             :         /* ignore autoresume if autoseek is switched off */
     800           3 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     801           1 :                 resumepos = 0;
     802             :         }
     803             : 
     804           3 :         if (ftp->autoseek && resumepos) {
     805             :                 /* if autoresume is wanted seek to end */
     806           2 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     807           1 :                         php_stream_seek(stream, 0, SEEK_END);
     808           1 :                         resumepos = php_stream_tell(stream);
     809             :                 } else {
     810           1 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     811             :                 }
     812             :         }
     813             : 
     814             :         /* configuration */
     815           3 :         ftp->direction = 0;   /* recv */
     816           3 :         ftp->closestream = 0; /* do not close */
     817             : 
     818           3 :         if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
     819           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     820           0 :                 RETURN_LONG(ret);
     821             :         }
     822             : 
     823           3 :         RETURN_LONG(ret);
     824             : }
     825             : /* }}} */
     826             : 
     827             : /* {{{ proto bool ftp_pasv(resource stream, bool pasv)
     828             :    Turns passive mode on or off */
     829           1 : PHP_FUNCTION(ftp_pasv)
     830             : {
     831             :         zval            *z_ftp;
     832             :         ftpbuf_t        *ftp;
     833             :         zend_bool       pasv;
     834             : 
     835           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &z_ftp, &pasv) == FAILURE) {
     836           1 :                 return;
     837             :         }
     838             : 
     839           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     840             : 
     841           0 :         if (!ftp_pasv(ftp, pasv ? 1 : 0)) {
     842           0 :                 RETURN_FALSE;
     843             :         }
     844             : 
     845           0 :         RETURN_TRUE;
     846             : }
     847             : /* }}} */
     848             : 
     849             : /* {{{ proto bool ftp_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     850             :    Retrieves a file from the FTP server and writes it to a local file */
     851           5 : PHP_FUNCTION(ftp_get)
     852             : {
     853             :         zval            *z_ftp;
     854             :         ftpbuf_t        *ftp;
     855             :         ftptype_t       xtype;
     856             :         php_stream      *outstream;
     857             :         char            *local, *remote;
     858             :         size_t          local_len, remote_len;
     859           5 :         zend_long               mode, resumepos=0;
     860             : 
     861           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     862           1 :                 return;
     863             :         }
     864             : 
     865           4 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     866           4 :         XTYPE(xtype, mode);
     867             : 
     868             :         /* ignore autoresume if autoseek is switched off */
     869           3 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     870           0 :                 resumepos = 0;
     871             :         }
     872             : 
     873             : #ifdef PHP_WIN32
     874             :         mode = FTPTYPE_IMAGE;
     875             : #endif
     876             : 
     877           3 :         if (ftp->autoseek && resumepos) {
     878           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     879           0 :                 if (outstream == NULL) {
     880           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     881             :                 }
     882           0 :                 if (outstream != NULL) {
     883             :                         /* if autoresume is wanted seek to end */
     884           0 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     885           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     886           0 :                                 resumepos = php_stream_tell(outstream);
     887             :                         } else {
     888           0 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     889             :                         }
     890             :                 }
     891             :         } else {
     892           3 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     893             :         }
     894             : 
     895           3 :         if (outstream == NULL)  {
     896           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
     897           0 :                 RETURN_FALSE;
     898             :         }
     899             : 
     900           3 :         if (!ftp_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) {
     901           1 :                 php_stream_close(outstream);
     902           1 :                 VCWD_UNLINK(local);
     903           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     904           1 :                 RETURN_FALSE;
     905             :         }
     906             : 
     907           2 :         php_stream_close(outstream);
     908           2 :         RETURN_TRUE;
     909             : }
     910             : /* }}} */
     911             : 
     912             : /* {{{ proto int ftp_nb_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     913             :    Retrieves a file from the FTP server nbhronly and writes it to a local file */
     914           3 : PHP_FUNCTION(ftp_nb_get)
     915             : {
     916             :         zval            *z_ftp;
     917             :         ftpbuf_t        *ftp;
     918             :         ftptype_t       xtype;
     919             :         php_stream      *outstream;
     920             :         char            *local, *remote;
     921             :         size_t          local_len, remote_len;
     922             :         int ret;
     923           3 :         zend_long               mode, resumepos=0;
     924             : 
     925           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     926           1 :                 return;
     927             :         }
     928             : 
     929           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     930           2 :         XTYPE(xtype, mode);
     931             : 
     932             :         /* ignore autoresume if autoseek is switched off */
     933           2 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     934           0 :                 resumepos = 0;
     935             :         }
     936             : #ifdef PHP_WIN32
     937             :         mode = FTPTYPE_IMAGE;
     938             : #endif
     939           3 :         if (ftp->autoseek && resumepos) {
     940           1 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     941           1 :                 if (outstream == NULL) {
     942           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     943             :                 }
     944           1 :                 if (outstream != NULL) {
     945             :                         /* if autoresume is wanted seek to end */
     946           1 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     947           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     948           0 :                                 resumepos = php_stream_tell(outstream);
     949             :                         } else {
     950           1 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     951             :                         }
     952             :                 }
     953             :         } else {
     954           1 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     955             :         }
     956             : 
     957           2 :         if (outstream == NULL)  {
     958           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
     959           0 :                 RETURN_FALSE;
     960             :         }
     961             : 
     962             :         /* configuration */
     963           2 :         ftp->direction = 0;   /* recv */
     964           2 :         ftp->closestream = 1; /* do close */
     965             : 
     966           2 :         if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
     967           0 :                 php_stream_close(outstream);
     968           0 :                 ftp->stream = NULL;
     969           0 :                 VCWD_UNLINK(local);
     970           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     971           0 :                 RETURN_LONG(PHP_FTP_FAILED);
     972             :         }
     973             : 
     974           2 :         if (ret == PHP_FTP_FINISHED){
     975           0 :                 php_stream_close(outstream);
     976           0 :                 ftp->stream = NULL;
     977             :         }
     978             : 
     979           2 :         RETURN_LONG(ret);
     980             : }
     981             : /* }}} */
     982             : 
     983             : /* {{{ proto int ftp_nb_continue(resource stream)
     984             :    Continues retrieving/sending a file nbronously */
     985           8 : PHP_FUNCTION(ftp_nb_continue)
     986             : {
     987             :         zval            *z_ftp;
     988             :         ftpbuf_t        *ftp;
     989             :         zend_long               ret;
     990             : 
     991           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     992           1 :                 return;
     993             :         }
     994             : 
     995           7 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     996             : 
     997           7 :         if (!ftp->nb) {
     998           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "no nbronous transfer to continue.");
     999           1 :                 RETURN_LONG(PHP_FTP_FAILED);
    1000             :         }
    1001             : 
    1002           6 :         if (ftp->direction) {
    1003           0 :                 ret=ftp_nb_continue_write(ftp TSRMLS_CC);
    1004             :         } else {
    1005           6 :                 ret=ftp_nb_continue_read(ftp TSRMLS_CC);
    1006             :         }
    1007             : 
    1008           6 :         if (ret != PHP_FTP_MOREDATA && ftp->closestream) {
    1009           1 :                 php_stream_close(ftp->stream);
    1010           1 :                 ftp->stream = NULL;
    1011             :         }
    1012             : 
    1013           6 :         if (ret == PHP_FTP_FAILED) {
    1014           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1015             :         }
    1016             : 
    1017           6 :         RETURN_LONG(ret);
    1018             : }
    1019             : /* }}} */
    1020             : 
    1021             : /* {{{ proto bool ftp_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1022             :    Stores a file from an open file to the FTP server */
    1023           2 : PHP_FUNCTION(ftp_fput)
    1024             : {
    1025             :         zval            *z_ftp, *z_file;
    1026             :         ftpbuf_t        *ftp;
    1027             :         ftptype_t       xtype;
    1028             :         size_t          remote_len;
    1029           2 :         zend_long               mode, startpos=0;
    1030             :         php_stream      *stream;
    1031             :         char            *remote;
    1032             : 
    1033           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1034           1 :                 return;
    1035             :         }
    1036             : 
    1037           1 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1038           1 :         php_stream_from_zval(stream, z_file);
    1039           1 :         XTYPE(xtype, mode);
    1040             : 
    1041             :         /* ignore autoresume if autoseek is switched off */
    1042           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1043           0 :                 startpos = 0;
    1044             :         }
    1045             : 
    1046           0 :         if (ftp->autoseek && startpos) {
    1047             :                 /* if autoresume is wanted ask for remote size */
    1048           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1049           0 :                         startpos = ftp_size(ftp, remote);
    1050           0 :                         if (startpos < 0) {
    1051           0 :                                 startpos = 0;
    1052             :                         }
    1053             :                 }
    1054           0 :                 if (startpos) {
    1055           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1056             :                 }
    1057             :         }
    1058             : 
    1059           0 :         if (!ftp_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) {
    1060           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1061           0 :                 RETURN_FALSE;
    1062             :         }
    1063             : 
    1064           0 :         RETURN_TRUE;
    1065             : }
    1066             : /* }}} */
    1067             : 
    1068             : /* {{{ proto int ftp_nb_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1069             :    Stores a file from an open file to the FTP server nbronly */
    1070           2 : PHP_FUNCTION(ftp_nb_fput)
    1071             : {
    1072             :         zval            *z_ftp, *z_file;
    1073             :         ftpbuf_t        *ftp;
    1074             :         ftptype_t       xtype;
    1075             :         size_t          remote_len;
    1076             :         int             ret;
    1077           2 :         zend_long       mode, startpos=0;
    1078             :         php_stream      *stream;
    1079             :         char            *remote;
    1080             : 
    1081           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1082           1 :                 return;
    1083             :         }
    1084             : 
    1085           1 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1086           1 :         php_stream_from_zval(stream, z_file);
    1087           1 :         XTYPE(xtype, mode);
    1088             : 
    1089             :         /* ignore autoresume if autoseek is switched off */
    1090           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1091           0 :                 startpos = 0;
    1092             :         }
    1093             : 
    1094           0 :         if (ftp->autoseek && startpos) {
    1095             :                 /* if autoresume is wanted ask for remote size */
    1096           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1097           0 :                         startpos = ftp_size(ftp, remote);
    1098           0 :                         if (startpos < 0) {
    1099           0 :                                 startpos = 0;
    1100             :                         }
    1101             :                 }
    1102           0 :                 if (startpos) {
    1103           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1104             :                 }
    1105             :         }
    1106             : 
    1107             :         /* configuration */
    1108           0 :         ftp->direction = 1;   /* send */
    1109           0 :         ftp->closestream = 0; /* do not close */
    1110             : 
    1111           0 :         if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) == PHP_FTP_FAILED)) {
    1112           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1113           0 :                 RETURN_LONG(ret);
    1114             :         }
    1115             : 
    1116           0 :         RETURN_LONG(ret);
    1117             : }
    1118             : /* }}} */
    1119             : 
    1120             : 
    1121             : /* {{{ proto bool ftp_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1122             :    Stores a file on the FTP server */
    1123           3 : PHP_FUNCTION(ftp_put)
    1124             : {
    1125             :         zval            *z_ftp;
    1126             :         ftpbuf_t        *ftp;
    1127             :         ftptype_t       xtype;
    1128             :         char            *remote, *local;
    1129             :         size_t          remote_len, local_len;
    1130           3 :         zend_long               mode, startpos=0;
    1131             :         php_stream      *instream;
    1132             : 
    1133           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1134           1 :                 return;
    1135             :         }
    1136             : 
    1137           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1138           2 :         XTYPE(xtype, mode);
    1139             : 
    1140           2 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1141           0 :                 RETURN_FALSE;
    1142             :         }
    1143             : 
    1144             :         /* ignore autoresume if autoseek is switched off */
    1145           2 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1146           0 :                 startpos = 0;
    1147             :         }
    1148             : 
    1149           2 :         if (ftp->autoseek && startpos) {
    1150             :                 /* if autoresume is wanted ask for remote size */
    1151           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1152           0 :                         startpos = ftp_size(ftp, remote);
    1153           0 :                         if (startpos < 0) {
    1154           0 :                                 startpos = 0;
    1155             :                         }
    1156             :                 }
    1157           0 :                 if (startpos) {
    1158           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1159             :                 }
    1160             :         }
    1161             : 
    1162           2 :         if (!ftp_put(ftp, remote, instream, xtype, startpos TSRMLS_CC)) {
    1163           0 :                 php_stream_close(instream);
    1164           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1165           0 :                 RETURN_FALSE;
    1166             :         }
    1167           2 :         php_stream_close(instream);
    1168             : 
    1169           2 :         RETURN_TRUE;
    1170             : }
    1171             : /* }}} */
    1172             : 
    1173             : 
    1174             : /* {{{ proto int ftp_nb_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1175             :    Stores a file on the FTP server */
    1176           1 : PHP_FUNCTION(ftp_nb_put)
    1177             : {
    1178             :         zval            *z_ftp;
    1179             :         ftpbuf_t        *ftp;
    1180             :         ftptype_t       xtype;
    1181             :         char            *remote, *local;
    1182             :         size_t          remote_len, local_len;
    1183           1 :         zend_long               mode, startpos=0, ret;
    1184             :         php_stream      *instream;
    1185             : 
    1186           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1187           1 :                 return;
    1188             :         }
    1189             : 
    1190           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1191           0 :         XTYPE(xtype, mode);
    1192             : 
    1193           0 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1194           0 :                 RETURN_FALSE;
    1195             :         }
    1196             : 
    1197             :         /* ignore autoresume if autoseek is switched off */
    1198           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1199           0 :                 startpos = 0;
    1200             :         }
    1201             : 
    1202           0 :         if (ftp->autoseek && startpos) {
    1203             :                 /* if autoresume is wanted ask for remote size */
    1204           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1205           0 :                         startpos = ftp_size(ftp, remote);
    1206           0 :                         if (startpos < 0) {
    1207           0 :                                 startpos = 0;
    1208             :                         }
    1209             :                 }
    1210           0 :                 if (startpos) {
    1211           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1212             :                 }
    1213             :         }
    1214             : 
    1215             :         /* configuration */
    1216           0 :         ftp->direction = 1;   /* send */
    1217           0 :         ftp->closestream = 1; /* do close */
    1218             : 
    1219           0 :         ret = ftp_nb_put(ftp, remote, instream, xtype, startpos TSRMLS_CC);
    1220             : 
    1221           0 :         if (ret != PHP_FTP_MOREDATA) {
    1222           0 :                 php_stream_close(instream);
    1223           0 :                 ftp->stream = NULL;
    1224             :         }
    1225             : 
    1226           0 :         if (ret == PHP_FTP_FAILED) {
    1227           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1228             :         }
    1229             : 
    1230           0 :         RETURN_LONG(ret);
    1231             : }
    1232             : /* }}} */
    1233             : 
    1234             : /* {{{ proto int ftp_size(resource stream, string filename)
    1235             :    Returns the size of the file, or -1 on error */
    1236           3 : PHP_FUNCTION(ftp_size)
    1237             : {
    1238             :         zval            *z_ftp;
    1239             :         ftpbuf_t        *ftp;
    1240             :         char            *file;
    1241             :         size_t          file_len;
    1242             : 
    1243           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1244           1 :                 return;
    1245             :         }
    1246             : 
    1247           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1248             : 
    1249             :         /* get file size */
    1250           2 :         RETURN_LONG(ftp_size(ftp, file));
    1251             : }
    1252             : /* }}} */
    1253             : 
    1254             : /* {{{ proto int ftp_mdtm(resource stream, string filename)
    1255             :    Returns the last modification time of the file, or -1 on error */
    1256           8 : PHP_FUNCTION(ftp_mdtm)
    1257             : {
    1258             :         zval            *z_ftp;
    1259             :         ftpbuf_t        *ftp;
    1260             :         char            *file;
    1261             :         size_t          file_len;
    1262             : 
    1263           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1264           1 :                 return;
    1265             :         }
    1266             : 
    1267           7 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1268             : 
    1269             :         /* get file mod time */
    1270           7 :         RETURN_LONG(ftp_mdtm(ftp, file));
    1271             : }
    1272             : /* }}} */
    1273             : 
    1274             : /* {{{ proto bool ftp_rename(resource stream, string src, string dest)
    1275             :    Renames the given file to a new path */
    1276           1 : PHP_FUNCTION(ftp_rename)
    1277             : {
    1278             :         zval            *z_ftp;
    1279             :         ftpbuf_t        *ftp;
    1280             :         char            *src, *dest;
    1281             :         size_t          src_len, dest_len;
    1282             : 
    1283           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &src, &src_len, &dest, &dest_len) == FAILURE) {
    1284           1 :                 return;
    1285             :         }
    1286             : 
    1287           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1288             : 
    1289             :         /* rename the file */
    1290           0 :         if (!ftp_rename(ftp, src, dest)) {
    1291           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1292           0 :                 RETURN_FALSE;
    1293             :         }
    1294             : 
    1295           0 :         RETURN_TRUE;
    1296             : }
    1297             : /* }}} */
    1298             : 
    1299             : /* {{{ proto bool ftp_delete(resource stream, string file)
    1300             :    Deletes a file */
    1301           2 : PHP_FUNCTION(ftp_delete)
    1302             : {
    1303             :         zval            *z_ftp;
    1304             :         ftpbuf_t        *ftp;
    1305             :         char            *file;
    1306             :         size_t          file_len;
    1307             : 
    1308           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &file, &file_len) == FAILURE) {
    1309           1 :                 return;
    1310             :         }
    1311             : 
    1312           1 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1313             : 
    1314             :         /* delete the file */
    1315           1 :         if (!ftp_delete(ftp, file)) {
    1316           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1317           1 :                 RETURN_FALSE;
    1318             :         }
    1319             : 
    1320           0 :         RETURN_TRUE;
    1321             : }
    1322             : /* }}} */
    1323             : 
    1324             : /* {{{ proto bool ftp_site(resource stream, string cmd)
    1325             :    Sends a SITE command to the server */
    1326           1 : PHP_FUNCTION(ftp_site)
    1327             : {
    1328             :         zval            *z_ftp;
    1329             :         ftpbuf_t        *ftp;
    1330             :         char            *cmd;
    1331             :         size_t          cmd_len;
    1332             : 
    1333           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
    1334           1 :                 return;
    1335             :         }
    1336             : 
    1337           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1338             : 
    1339             :         /* send the site command */
    1340           0 :         if (!ftp_site(ftp, cmd)) {
    1341           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1342           0 :                 RETURN_FALSE;
    1343             :         }
    1344             : 
    1345           0 :         RETURN_TRUE;
    1346             : }
    1347             : /* }}} */
    1348             : 
    1349             : /* {{{ proto bool ftp_close(resource stream)
    1350             :    Closes the FTP stream */
    1351          12 : PHP_FUNCTION(ftp_close)
    1352             : {
    1353             :         zval            *z_ftp;
    1354             :         ftpbuf_t        *ftp;
    1355             : 
    1356          12 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
    1357           1 :                 return;
    1358             :         }
    1359             : 
    1360          11 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1361             : 
    1362          11 :         ftp_quit(ftp);
    1363             : 
    1364          11 :         RETURN_BOOL(zend_list_close(Z_RES_P(z_ftp)) == SUCCESS);
    1365             : }
    1366             : /* }}} */
    1367             : 
    1368             : /* {{{ proto bool ftp_set_option(resource stream, int option, mixed value)
    1369             :    Sets an FTP option */
    1370           3 : PHP_FUNCTION(ftp_set_option)
    1371             : {
    1372             :         zval            *z_ftp, *z_value;
    1373             :         zend_long               option;
    1374             :         ftpbuf_t        *ftp;
    1375             : 
    1376           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &z_ftp, &option, &z_value) == FAILURE) {
    1377           1 :                 return;
    1378             :         }
    1379             : 
    1380           2 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1381             : 
    1382           2 :         switch (option) {
    1383             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1384           0 :                         if (Z_TYPE_P(z_value) != IS_LONG) {
    1385           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option TIMEOUT_SEC expects value of type long, %s given",
    1386             :                                         zend_zval_type_name(z_value));
    1387           0 :                                 RETURN_FALSE;
    1388             :                         }
    1389           0 :                         if (Z_LVAL_P(z_value) <= 0) {
    1390           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
    1391           0 :                                 RETURN_FALSE;
    1392             :                         }
    1393           0 :                         ftp->timeout_sec = Z_LVAL_P(z_value);
    1394           0 :                         RETURN_TRUE;
    1395             :                         break;
    1396             :                 case PHP_FTP_OPT_AUTOSEEK:
    1397           6 :                         if (Z_TYPE_P(z_value) != IS_TRUE && Z_TYPE_P(z_value) != IS_FALSE) {
    1398           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option AUTOSEEK expects value of type boolean, %s given",
    1399             :                                         zend_zval_type_name(z_value));
    1400           0 :                                 RETURN_FALSE;
    1401             :                         }
    1402           4 :                         ftp->autoseek = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0;
    1403           2 :                         RETURN_TRUE;
    1404             :                         break;
    1405             :                 default:
    1406           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%pd'", option);
    1407           0 :                         RETURN_FALSE;
    1408             :                         break;
    1409             :         }
    1410             : }
    1411             : /* }}} */
    1412             : 
    1413             : /* {{{ proto mixed ftp_get_option(resource stream, int option)
    1414             :    Gets an FTP option */
    1415           1 : PHP_FUNCTION(ftp_get_option)
    1416             : {
    1417             :         zval            *z_ftp;
    1418             :         zend_long               option;
    1419             :         ftpbuf_t        *ftp;
    1420             : 
    1421           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_ftp, &option) == FAILURE) {
    1422           1 :                 return;
    1423             :         }
    1424             : 
    1425           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1426             : 
    1427           0 :         switch (option) {
    1428             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1429           0 :                         RETURN_LONG(ftp->timeout_sec);
    1430             :                         break;
    1431             :                 case PHP_FTP_OPT_AUTOSEEK:
    1432           0 :                         RETURN_BOOL(ftp->autoseek);
    1433             :                         break;
    1434             :                 default:
    1435           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%pd'", option);
    1436           0 :                         RETURN_FALSE;
    1437             :                         break;
    1438             :         }
    1439             : }
    1440             : /* }}} */
    1441             : 
    1442             : #endif /* HAVE_FTP */
    1443             : 
    1444             : /*
    1445             :  * Local variables:
    1446             :  * tab-width: 4
    1447             :  * c-basic-offset: 4
    1448             :  * indent-tabs-mode: t
    1449             :  * End:
    1450             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:15 +0000 (4 days ago)

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