Jump to content

Why doesn't this work? (SSH2)


ChrisMartino

Recommended Posts

This is my script:

 

<?php
$connection = ssh2_connect('213.251.167.109', 22);
ssh2_auth_password($connection, 'root', 'MGdgfskc');

$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');
?>

 

This is my errors:

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

 

Link to comment
Share on other sites

Well, if the function doesn't exist then obviously the extension is not installed. How did you verify that it's installed? Check the output of phpinfo(). It'll give you info about your PHP environment.

 

Also try to run

<?php
var_dump(extension_loaded('ssh2'));

 

If that doesn't output true then it is not installed.

 

See get_loaded_extensions as well.

Link to comment
Share on other sites

  • 1 month later...

This is my script:

 

<?php
$connection = ssh2_connect('213.251.167.109', 22);
ssh2_auth_password($connection, 'root', 'MGdgfskc');

$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');
?>

 

This is my errors:

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

I was having this very problem but gave up and just wound up utilizing a pure-PHP implementation of SSH - phpSecLib:

 

http://phpseclib.sourceforge.net/

 

Even if you can get the ssh2 extension compiled you'll still have problems with ssh2_exec returning prematurely.  phpSecLib, in contrast, works perfectly.  It requires zero effort to get working and it works every time, too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.