Skip to content

Instantly share code, notes, and snippets.

@mbrowne
Created March 6, 2013 17:08
Show Gist options
  • Save mbrowne/5101004 to your computer and use it in GitHub Desktop.
Save mbrowne/5101004 to your computer and use it in GitHub Desktop.
SSH Connection from CodeIgniter
<?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);
}
}
Copy link

ghost commented Mar 8, 2013

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

@AnwarQasem
Copy link

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