SSH to the server and get result (PHP) !

Discussion in 'PHP' started by Shyamin Ayesh, Sep 2, 2013.

  1. #1
    i'm make ssh conneting to my server using "ssh2_connect" function. now i need to execute command and get the return result and echo in the result in the php. "ssh2_connect" is working perfect but i don't know how to execute and get results from the command using this connection. please can you help me to do this. here is my code part for the ssh connectin.

    <?php
    
    $connection = ssh2_connect('www.example.com', 22);
    
    if (ssh2_auth_password($connection, 'root', 'samplepassword')) {
      echo "Authentication Successful!\n";
    } else {
      die('Authentication Failed...');
    }
    
    ?>
    Code (markup):
    thank you !
     
    Shyamin Ayesh, Sep 2, 2013 IP
  2. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    100
  3. Shyamin Ayesh

    Shyamin Ayesh Active Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    76
    #3
    i try using ss2_exec function ... but it not give me the return result ... can anyone please explain me how to do it ...
     
    Shyamin Ayesh, Sep 3, 2013 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    ThePHPMaster, Sep 4, 2013 IP