www.webdeveloper.com
Results 1 to 5 of 5

Thread: ssh2 response?

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Posts
    61

    Arrow ssh2 response?

    Hey!

    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

    Code:
    $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;
    	}
    
    	fclose($stream);
    	
    	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?

    //Artheus

  2. #2
    Join Date
    Aug 2009
    Posts
    84
    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(...)

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    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
    Posts
    61
    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
    Posts
    9
    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



Recent Articles