Created
April 25, 2018 06:58
-
-
Save komeiji-satori/eef10fcbaf1301b7e8db8192788a5792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function remote_exec($host = null, $port = null, $auth = [], $commands = []) | |
{ | |
$result = []; | |
$connection = ssh2_connect($host, $port); | |
if ($auth["type"] == "pubkey") { | |
ssh2_auth_pubkey_file($connection, $auth["username"], $auth["public_key"], $auth["private_key"], $auth["password"]); | |
} else { | |
ssh2_auth_password($connection, $auth["username"], $auth["password"]); | |
} | |
foreach ($commands as $command) { | |
$stream = ssh2_exec($connection, $command); | |
stream_set_blocking($stream, true); | |
$result[] = stream_get_contents($stream); | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment