История изменений
Исправление
snoopcat,
(текущая версия)
:
<?php
function ssh_login($ip, $port, $user, $password) {
if(!$conn = ssh2_connect("$ip", $port)) return("Can't connect to $ip");
if(!ssh2_auth_password($conn, "$user", "$password")) return("Can't auth with $user, $password");
return $conn;
}
function ssh_exec($link, $cmd) {
$stream = ssh2_exec($link,"$cmd");
stream_set_blocking($stream,true);
$data = '';
while($buf = fread($stream,4096)) {
$data .= $buf;
}
return $data;
}
$link = ssh_login("localhost", 22, "root", "verysecretpassword");
$result = ssh_exec($link, "ls -la");
echo $result;
?>
Исправление
snoopcat,
:
<?php
function ssh_login($ip, $port, $user, $password) {
if(!$conn = ssh2_connect("$ip", $port)) return("Can't connect to $ip");
if(!ssh2_auth_password($conn, "$user", "$password")) return("Can't auth with $user, $password");
return $conn;
}
function ssh_exec($link, $cmd) {
$stream = ssh2_exec($link,"$cmd");
stream_set_blocking($stream,true);
$data = '';
while($buf = fread($stream,4096)) {
$data .= $buf;
}
return $data;
}
$link = ssh_login("localhost", 22, "root", "verysecretpassword");
$result = ssh_exec($link, "ls -la");
echo $result;
?>
Исходная версия
snoopcat,
:
<?php
function ssh_login($ip, $port, $user, $password) {
if(!$conn = ssh2_connect("$ip", $port)) return("Can't connect to $ip");
if(!ssh2_auth_password($conn, "$user", "$password")) return("Can't auth with $user, $password");
return $conn;
}
function ssh_exec($link, $cmd) {
$stream = ssh2_exec($link,"$cmd");
stream_set_blocking($stream,true);
$data = '';
while($buf = fread($stream,4096)) {
$data .= $buf;
}
return $data;
}
$link = ssh_login("localhost", 22, "root", "verysecretpassword");
$result = ssh_exec($link, "ls -la");
echo $result;
?>