I am trying to prepare PHP script with the new server nginx web server.
Unfortunately, I havent dealt with SSH2 before for php.
Maybe some good forum would be able to help me with this?
You can do SSH in PHP with http://phpseclib.sourceforge.net/ . eg.
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
Related
I'm trying to connect to a server in my PHP code via SSH (using the Net_SSH2 class), and run a number of commands on the remote server.
The remote server outputs bash: runmqsc: command not found.
The odd thing is, that the exact same command is found and functional on that server, when I SSH to it using MobaXterm.
I validated that the code uses the correct hostname, user and password to connect.
Any ideas?
This is what I'm doing in PHP:
$this->ssh = new Net_SSH2("myhost");
$this->ssh->login("myuser", "mypass");
$command = "runmqsc MyQmgr \n DEFINE QLOCAL(MY_QUEUE) \n end \n";
$this->ssh->exec($command);
You probably need to do something more like this:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->read('username#username:~$');
$ssh->write("runmqsc MyQmgr\n"); // note the "\n"
echo $ssh->read('username#username:~$'); // or whatever the prompt is - does runmqsc have it's own prompt?
$ssh->write("DEFINE QLOCAL(MY_QUEUE)\n");
?>
...etc...
I want to connect to another server by ssh using PHP but i get error as below .i looked for it very much but couldn't find any suitable solution for me.
Warning: ssh2_connect(): Error starting up SSH connection(-1): Failed sending banner in ...
Warning: ssh2_connect(): Unable to connect to ...
this is my php code :
$connection = ssh2_connect($details[0]['address'], $details[0]['port']);
ssh2_auth_password($connection, $details[0]['username'], $details[0]['password']);
Trying to diagnose issues with libssh2 is nigh impossible. My recommendation: use phpseclib, a pure PHP SSH implementation, and assuming that doesn't resolve the issue you can get logs that'll assist in the diagnosis. eg.
<?php
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
echo $ssh->getLog();
?>
i will exec SSH2 commands in Laravel 4 and catch the output to print it on the screen.
But not on the same root as where is Laravel is running. I will exec the commands on other roots. Is see that Laravel is using phpseclib.
How can i use the same phpseclib functionality of this code but in laravel 4 format:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
I need the output of the exec.
Hope for help thx
Are there any possibilities to connect to server via ssh using php in tidesdk.
I'm trying to use
$session = ssh2_connect($server, 22);
But an error occurred
Fatal error - Call to undefined function ssh2_connect()
I'd recommend using phpseclib, a pure PHP SSH implementation. eg.
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
The fact that it's pure-PHP means it's ultra-portable. Unlike the libssh2 extension you're currently trying to use.
Have you installed the SSH2 extension?
http://ie1.php.net/manual/en/ssh2.installation.php
I need to use ssh on php. I eanble these two dlls in php.ini file:
extension=php_ssh2.dll
extension=php_ssh2.dll
I am still getting this error, any ideas what I might be missing?'
Fatal error: Call to undefined function ssh2_connect()
You probably need the libssh2 DLL's too.
I think phpseclib, a pure PHP SSH2 implementation, would work better for you actually. eg.
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>