Results 1 to 5 of 5

Thread: ssh2 response?

  1. #1
    Join Date
    Sep 2008

    Arrow ssh2 response?


    I'm building a simple php app, so that I can control my server through a browser.

    This is a short version of the app

    $user = $_POST['user']; //the username, sent with post-method from form.
    $pass = $_POST['pass']; //the password, sent with post-method from form.
    $query = $_POST['query']; //the shell command, sent with post-method from form.
    $ssh = ssh2_connect("localhost");
    ssh2_auth_password($ssh, $user, $pass);
    if($stream = ssh2_exec($ssh, $query)) {					
    	$result = "";
    	while( $buf = fread($stream,4096) ){
    		$result .= $buf;
    	echo $result;
    Well the problem is that I can't get the response sent from the server. I guess I am using the wrong way of getting it. I've tried a couple of different methods, but I can't get anything.

    I know for a fact that the php-ssh2 runs the shell command on the server. But never get any response from the server.. A little frustrating.

    Any one?


  2. #2
    Join Date
    Aug 2009
    Hi, as far as I remember after ssh2_connect(...) you need to call ssh2_fingerprint($ssh) to get ssh server fingerprint before calling ssh2_auth_password(...)

    Support Chat software for your website

  3. #3
    Join Date
    Nov 2008
    Is your shell command actually outputting anything? If you're just executing a program which does not print anything to stdout then you won't have anything in the stream to read. What happens if you try a 'ls -l' or some other command which definitely outputs results?

  4. #4
    Join Date
    Sep 2008
    Well... The command I'm trying is df -h. And as far as I know that should make an output.

  5. #5
    Join Date
    Mar 2010
    Maybe try phpseclib: a pure php ssh implementation? Unlike the PECL ssh2 extension, phpseclib's author actively provides support, as can be seen by looking at the support forum. Also, frankly, it offers more debugging capabilities than the PECL ssh2 extension does, with such things as $ssh->getLog() and $ssh->getLastError().

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center