Re: [PHP] lib ssh2 functions and ssh2_exec stream reading work around

2005-05-16 Thread Shawn McKnight
I ran in to many ssh2 stream problems as well.
Problem 1.
One problem I think related to the openssl version I was using.
I was using the standard version with Fedora Core 3. ssh connected actions
sometimes worked and sometimes did not work.
I recompiled the ssh2.so with the following versions.
libssh2-0.8
openssl-0.9.7g
ssh2-0.7
Problem 2.
At this point file transfers worked great. However, running commands and
reading the stream was having problems.
Using the classic
?
| while (!feof($ssh_stream)) {
 $contents .= fread($||ssh_stream||, 5120);
}
?
I found that I never got any responses.
After testing I found that my $||ssh_stream always had a true response 
to feof($||ssh_stream||)|;
And that  fread($ssh_stream,5120) did not always bring back data.

While the following is not a Correction to the problem, it does allow 
you to read the incoming stream
and know when it is done computing. This is the function I use which is 
in side a remoteConnection
class I have wrapping the different ssh2 functions. If somebody comes up 
with a CORRECTIOIN to
the problem rather than a work around, I would surely appreciate it.

Here is my work around with comments. Hope it helps.
?
   function command ($command) {
// attach echo '__end_cmd_response__'; to the end of any 
command run.
// this will be the last thing in the streams output so I 
can identify when my command
// has finished.
   $stream = ssh2_exec($this-conn, $command .\necho 
'__end_cmd_response__'; );
   if ($stream) {
   // not fully sure why I do this. but it does not seem to 
hurt. The stream has no data
   // right away.
   sleep(5);
   // turning blocking off allows stream to keep moving 
eventhough no data is coming
   // through it. Required to make the time out work correctly.
   socket_set_blocking($stream,false);
   // the time out is set less than the php time out. 
Otherwise you run the risk of the
   // php timing out if the stream hangs.
   stream_set_timeout($stream,25);
   $start = mktime();
   // manual indicator to exit the while
   $exit = false;
   while ($exit == false) {
   $read .= fread($stream,5120);
// this pulls meta data from the stram so we can 
test for the time out.
   $info = stream_get_meta_data($stream);
// test for the echo'ed __end_cmd_response__
   if (ereg(__end_cmd_response__,$read)) {
   $exit = true;
   break;
   // check to see if the stream has timed out.
   } elseif ($info[timed_out]) {
// i just add this to tell the user that the 
stream timed out.
   $read .= iExited stream reading (25 seconds). 
Check changes online./i\n;
   $exit = true;
   break;
   }
   }
   fclose($stream);
   return $read;
   }

?
Oscar Gosdinski wrote:
Hello everybody:
I need my PHP application connects through SSH to other server for
getting some info to display and i tried the following code to test
lib ssh2:
$server = ...;
$user = ...;
$passwd = ...;
$con = ssh2_connect($server, 22);
if (ssh2_auth_password($con, $user, $passwd)) {
  $s = ssh2_exec($con, 'ls -l');
  $file = fopen(/tmp/test, w);
  while ($line = stream_get_line($s, 1024)) {
  fwrite($file, $line);
  fflush($file);
  }
  fclose($file);
} else {
  echo Authentication Error;
}
The file /tmp/test was created but it does not have any data. I can
connect to the server using a normal ssh session in my laptop and the
'ls -l' command returns me information.
I think that i installed correctly the ssh2 functions because if a put
an incorrect password i get the Authentication Error message.
I searched the web for info about similar problems and no results.
Please, anyone can help me with this problem because i have been
spending three days with this.
Thanks in advance for your answers.
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ftp_ssl_connect() Problem

2003-05-27 Thread Shawn McKnight

I too am having problems getting ftp_ssl_connect() enabled, any help is very
appreciated.

What I am using is as follows, please let me know what it is I am missing..

PHP 4.3.0 installed as a Static Module with Apache 1.3.24

This is a re-configuration of an existing installation of PHP 4.3.0
I have never had problems reconfiguring PHP as I needed the other options
I use.

My configure command was
./configure \
 --enable-sockets \
 --enable-ftp \
 --with-mysql=/usr/local/mysql \
 --with-apache=../apache_1.3.24 \
 --with-png-dir=/root/backup/image/libpng-1.2.5 \
 --with-jpeg-dir=/root/backup/image/jpeg-6b \
 --with-gd=/usr/local/gd \
 --with-zlib-dir=/usr/local \
 --with-openssl=/usr/local/ssl

My infophp() says..

OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.6b [engine] 9 Jul 2001

However the general info says :

Build Date Feb 25 2003 11:00:45
(this was about the last time I made a successful change,
obviously not today)

Configure Command  
'./configure' '--with-mysql=/usr/local/mysql'
'--with-apache=../apache_1.3.24'
'--with-png-dir=/root/backup/image/libpng-1.2.5'
'--with-jpeg-dir=/root/backup/image/jpeg-6b'
'--with-gd=/usr/local/gd'
'--with-zlib-dir=/usr/local'
'--enable-sockets' 
'--enable-ftp' 
(this command reflects my last successful change and lacks the
'--with-openssl=/usr/local/ssl' I would have expected)

Thanks for any help that can be provided.

From my understanding PHP 4.3.0 and OpenSSL 0.9.6 should work.

Thanks again. -Shawn


Shawn McKnight
Circumerro Inc.
307-733-8319 x222
[EMAIL PROTECTED]

We are the music makers, we are the dreamers of the dream.
 - Willy Wonka


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php