Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP function ssh2_connect is not working

Tags:

php

ssh

Following is my script:

    <?php     $connection = ssh2_connect('XX.XX.XX.XX', 22);     ssh2_auth_password($connection, 'root', '******');      $stream = ssh2_exec($connection, 'useradd -d /home/users/test -m testftp');     $stream = ssh2_exec($connection, 'passwd testftp');     $stream = ssh2_exec($connection, 'password');     $stream = ssh2_exec($connection, 'password');     ?> 

It showing the following error:

Fatal error: Call to undefined function ssh2_connect() in /home/chaosnz/public_html/fotosnap.net/test.php on line 2 

How can I deal with this?

Thanks

like image 449
Ravi Soni Avatar asked Dec 27 '12 06:12

Ravi Soni


1 Answers

Honestly, I'd recommend using phpseclib, a pure PHP SSH2 implementation. Example:

<?php include('Net/SSH2.php');  $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) {     exit('Login Failed'); }  echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> 

It's a ton more portable, easier to use and more feature packed too.

like image 126
neubert Avatar answered Sep 26 '22 00:09

neubert