|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-12-14 11:06 UTC] metal3d at gmail dot com
 Description:
------------
Creating tunnel by command line ok:
ssh -N -f root@172.17.6.126 -L55959:localhost:80
But with php (same user, command line call):
PHP Warning:  ssh2_tunnel(): Unable to request a channel from remote host in /home/patricef/tmp/tunnel.php on line 4
What is the problem ?
See the code given to reproduce the bug
Reproduce code:
---------------
<?php
$connection = ssh2_connect('172.17.6.126', 22,array('hostkey'=>'ssh-rsa'));
ssh2_auth_pubkey_file($connection, 'root', '/home/patricef/.ssh/id_rsa.pub', '/home/patricef/.ssh/id_rsa');
$tunnel = ssh2_tunnel($connection, '172.28.1.4:80', 55655);
?>
Expected result:
----------------
I want to have my tunnel opened...
Actual result:
--------------
No backtrace
PHP Warning:  ssh2_tunnel(): Unable to request a channel from remote host in /home/patricef/tmp/tunnel.php on line 4
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 19:00:02 2025 UTC | 
OK, I have the same problem. What bothers me is the fact that no one seems to either answer the original question or to update the documentation. Actually, a good example is what we need. I have the same problem with ssh2_tunnel. $con=ssh2_connect($remote_host, 22); if (ssh2_auth_password($connection, $SSH_USER, $PASS)) { if ($tunnel = ssh2_tunnel($con, "$remote_host:$remote_port", $local_port)) echo "Tunnel OK"; else echo "Tunnel creation failed."; } Guess what. No tunnel is created! The message was: PHP Warning: ssh2_tunnel(): Unable to request a channel from remote host So, either I have not understood how to create a tunnel (since the manual is not very helpful on the issue), or the ssh2_tunnel does not work... Some notes: The ssh2_tunnel function uses 3 parameters. I thought that we need one more parameter! Now, function uses a host/port combination (which host is not clear). But either the local or the remote servers port is not given in the function! I suppose that this is the reason that my connection is failed. We need support here...You need to patch ssh2_fopen_wrappers.c file for ssh2_tunnel function if you want to specify source host and source port parameters.: open up ssh2_fopen_wrappers.c file. 1) CHANGE following line (LINE 1175 on ssh2 v0.10): if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &zsession, &host, &host_len, &port) == FAILURE) { TO if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl|sl", &zsession, &host, &host_len, &port, &shost, &shost_len, &sport) == FAILURE) { 2) CHANGE following line (LINE 1181 on ssh2 v0.10): stream = php_ssh2_direct_tcpip(session, Z_LVAL_P(zsession), host, port TSRMLS_CC); TO stream = php_ssh2_direct_tcpip(session, Z_LVAL_P(zsession), host, port, shost, sport TSRMLS_CC); 3) AFTER following lines (LINE 1172 on ssh2 v0.10): int host_len; long port; ADD char *shost = "127.0.0.1"; int shost_len; long sport = 22; 4) CHANGE following line (LINE 1065 on ssh2 v0.10): static php_stream *php_ssh2_direct_tcpip(LIBSSH2_SESSION *session, int resource_id, char *host, int port TSRMLS_DC) TO static php_stream *php_ssh2_direct_tcpip(LIBSSH2_SESSION *session, int resource_id, char *host, int port, char *shost, int sport TSRMLS_DC) 5) CHANGE following line (LINE 1071 on ssh2 v0.10): channel = libssh2_channel_direct_tcpip(session, host, port); TO channel = libssh2_channel_direct_tcpip_ex(session, host, port, shost, sport); 6) CHANGE following line (LINE 1138 on ssh2 v0.10): stream = php_ssh2_direct_tcpip(session, resource_id, host, port TSRMLS_CC); TO stream = php_ssh2_direct_tcpip(session, resource_id, host, port, shost, sport TSRMLS_CC); 7) AFTER following lines (LINE 1101 on ssh2 v0.10): int port = 0; int resource_id = 0; ADD char *shost = "127.0.0.1"; long sport = 22; Follow steps one-by-one and compile again. Tested on Fedora core 4 with libssh2 v0.18 and pecl/ssh2 v0.10 IMPORTANT NOTE: For older versions of ssh2 extension LINE numbers may be different. Do this only if you know what you do! ---- Volkan K.