Skip to content

Instantly share code, notes, and snippets.

@wayanjimmy
Created October 29, 2014 07:05
Show Gist options
  • Save wayanjimmy/5ad93e43cf1db6629fe4 to your computer and use it in GitHub Desktop.
Save wayanjimmy/5ad93e43cf1db6629fe4 to your computer and use it in GitHub Desktop.
Otomatisasi git pull dengan PHP ssh2_connect
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("host", "port"))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "username", "password")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, "command" ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
echo $data;
fclose($stream);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment