|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-02-21 21:25 UTC] jani@php.net
-Package: Feature/Change Request
+Package: FTP related
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 13:00:01 2025 UTC |
Description: ------------ The current ftp_connect function does not have the feature to bind the outgoing connections to a specific local IP. Yet this functionality is quite easily added. With my very very very basic cpp knowledge I managed to add this feature to the code. Imho it'd be a good idea to add something like this but properly coded to the ftp_ featureset :) A quick'n dirty changeset which converts ftp_connect(host,port,timeout) to ftp_connect(host,bindip,port) diff -urN php-5.1.4/ext/ftp/ftp.c php-5.1.4-ftpbind/ext/ftp/ftp.c --- php-5.1.4/ext/ftp/ftp.c 2006-04-03 11:14:33.000000000 +0200 +++ php-5.1.4-ftpbind/ext/ftp/ftp.c 2006-06-03 15:04:58.718141536 +0200 @@ -121,7 +121,7 @@ /* {{{ ftp_open */ ftpbuf_t* -ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC) +ftp_open(const char *host, const char *bindhost, short port, long timeout_sec TSRMLS_DC) { ftpbuf_t *ftp; socklen_t size; @@ -136,7 +136,7 @@ ftp->fd = php_network_connect_socket_to_host(host, (unsigned short) (port ? port : 21), SOCK_STREAM, - 0, &tv, NULL, NULL, NULL, 0 TSRMLS_CC); + 0, &tv, NULL, NULL, bindhost, 0 TSRMLS_CC); if (ftp->fd == -1) { goto bail; } diff -urN php-5.1.4/ext/ftp/ftp.h php-5.1.4-ftpbind/ext/ftp/ftp.h --- php-5.1.4/ext/ftp/ftp.h 2006-01-01 13:50:06.000000000 +0100 +++ php-5.1.4-ftpbind/ext/ftp/ftp.h 2006-06-03 15:04:58.718141536 +0200 @@ -93,7 +93,7 @@ /* open a FTP connection, returns ftpbuf (NULL on error) * port is the ftp port in network byte order, or 0 for the default */ -ftpbuf_t* ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC); +ftpbuf_t* ftp_open(const char *host, const char *bindhost, short port, long timeout_sec TSRMLS_DC); /* quits from the ftp session (it still needs to be closed) * return true on success, false on error diff -urN php-5.1.4/ext/ftp/php_ftp.c php-5.1.4-ftpbind/ext/ftp/php_ftp.c --- php-5.1.4/ext/ftp/php_ftp.c 2006-01-01 13:50:06.000000000 +0100 +++ php-5.1.4-ftpbind/ext/ftp/php_ftp.c 2006-06-03 15:04:58.718141536 +0200 @@ -147,17 +147,19 @@ } -/* {{{ proto resource ftp_connect(string host [, int port [, int timeout]]) +/* {{{ proto resource ftp_connect(string host [, string bindhost [, int port [, int timeout]]]) Opens a FTP stream */ PHP_FUNCTION(ftp_connect) { ftpbuf_t *ftp; char *host; + char *bindhost; int host_len; + int bindhost_len; long port = 0; long timeout_sec = FTP_DEFAULT_TIMEOUT; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s|ll", &host, &host_len, &bindhost, &bindhost_len, &port, &timeout_sec) == FAILURE) { return;