Created
March 6, 2013 17:08
-
-
Save mbrowne/5101004 to your computer and use it in GitHub Desktop.
SSH Connection from CodeIgniter
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 | |
class Test extends CI_Controller | |
{ | |
public function deploy_test() { | |
$connection = ssh2_connect("123.45.67.890", 23); | |
if(!$connection) { | |
echo json_encode('Connection failed'); | |
} | |
ssh2_auth_password($connection, "username", "password"); | |
$stream = ssh2_exec($connection, "ls -l"); | |
stream_get_blocking($stream, true); | |
$output = ""; | |
while($line = fgets($stream)) { | |
$output .= $line; | |
} | |
echo json_encode($line); | |
} | |
} |
you have a typo on "stream_set_blocking "
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Personally I think you'd be better off using phpseclib, a pure PHP SSH implementation. The following URL makes a pretty compelling case for it:
http://stackoverflow.com/questions/14304234/phpseclib-or-ssh2-pecl-extension?lq=1