Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

ssh - PHP function ssh2_connect is not working

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

question from:https://stackoverflow.com/questions/14050231/php-function-ssh2-connect-is-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...