Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: PHP ssh2 ubuntu

  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP ssh2 ubuntu

    Hello,

    im trying some new stuff in php and one is ssh2 now to exec a shell script on my ubuntu server. The problem is that nothing happends, i have tried alot of scripts that i found on the internet and no one works . For the moment i got this script and wanna see if anyone know whats wrong.

    PHP Code:
    <?php
    $connection 
    ssh2_connect('IP'port);
    ssh2_auth_password($connection'user''password');

    $stream ssh2_exec($connection'/home/mc/start.sh');
    ?>
    Just changed the connection things so i wont get hacked ^_^

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Assuming that IP and port are actually valid here.
    Start by enabling your error reporting. Any of those methods could be failing, but you're not checking the results of them.
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Next, handle the error checking on each:
    PHP Code:
    if ($con ssh2_connect('host'22))
    {
        if (
    ssh2_auth_password($con'user''password'))
        {
            
    $stream ssh2_exec($con'/home/mc/start.sh');
        }
        else
        {
            print 
    'Invalid username/password';
        }
    }
    else
    {
        print 
    'Failed to connect to host';

    Does that produce either error message?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Im getting a fatal error, Call to undefined function ssh2_connect() on line 6 and thats the
    PHP Code:
    if ($con ssh2_connect('213.67.233.164'22)) 
    Okey i tried on both my home server and a webhotel, at the webhotel i got the error because they miss an ssh2 extension but at home i got it. I get no errors
    at all. Just a white screen with nothing on it.
    Last edited by zubat; 02-01-2013 at 01:40 AM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    White screen would indicate with the above code that it executed properly. The undefined function indicates that the server isn't compiled with ssh2. The only real way around that is with socketing which is far less pleasant.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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