Answer the question
In order to leave comments, you need to log in
Apache x64 + php + ssh2 - what is the dog buried in?
There is installed apache 2.4.12 on win 7 x64, php 5.5.22.
Everything works great, but there was a need to work with pieces of iron via ssh.
Connected to php module php_ssh2.
When you run the script through the command line - everything works.
When launched in the site code through apache, the script falls off on "ssh2: unable to establish connection"
the code itself:
<?
if (!function_exists ("ssh2_connect")) die ("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect('хост', 22))){
echo "ssh: unable to establish connection\n";
} else {
// авторизуемся по имени пользователя и паролю
if(!ssh2_auth_password($con, "логин", "пароль")) {
echo "ssh: unable to authenticate\n";
} else {
// выполняем комманду
if (!($stream = ssh2_exec($con, "запрос" ))) {
} else {
stream_set_blocking ($stream, true);
$data_tmp = "";
while ($buf = fread ($stream,4096)) {$data_tmp .= $buf;}
fclose ($stream);
}
}
?>
Answer the question
In order to leave comments, you need to log in
After a long and painful search, I found out that this bundle has a problem.
The solution is the phpseclib library phpseclib.sourceforge.net/ssh/intro.html.
<?php
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$ssh = new Net_SSH2('host');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
echo $ssh->getLog();
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question