php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37690 Add feature to bind to ip for ftp_connect()
Submitted: 2006-06-03 22:59 UTC Modified: 2011-02-21 21:25 UTC
Votes:11
Avg. Score:4.6 ± 0.8
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:2 (22.2%)
From: jasper dot e at gmail dot com Assigned:
Status: Open Package: FTP related
PHP Version: 5.1.4 OS: Fedora Core 2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jasper dot e at gmail dot com
New email:
PHP Version: OS:

 

 [2006-06-03 22:59 UTC] jasper dot e at gmail dot com
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;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-21 21:25 UTC] jani@php.net
-Package: Feature/Change Request +Package: FTP related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC