phptelnet vs phpseclib
I am trying to connect a unix server from php and execute .exe (C language). Earlier I used phptelnet for this purpose, but now I need to shift to phpseclib due to security issues. I had 100% success rate when I use phptelnet. I could run some of the external programs like 'C' programs w开发者_如何转开发ith arguments as input in php script. In phptelnet I use
$telnet->DoCommand('cd public_html');
$telnet->DoCommand('cd abc');
$telnet->DoCommand('demo.exe');
$telnet->DoCommand("$inputs", $result);
echo $result;
This works perfect. But now I am using phpseclib. I could connect to the unix server via ssh and execute programs in which the inputs are hard coded in the program. I am using
echo $ssh->exec('./demo.exe');
Now the problem is how to provide inputs to the program. How can I use exec() to accept arguments as inputs. For example, demo.exe is a program to add two numbers. so can I say
echo $ssh->exec("./demo.exe, '10 20'");
Also how can I use exec() to execute multiple lnes of code in a single execution. I am a bit confused. Any inputs on this are greatly appreciated.
Thanks in advance.
Where you have multiple options to commands you'd use:
$ssh->exec("./demo.exe '10' '20'");
Leave out the comma, and enclose individual parameters each. Or convert a list with $opts = implode(" ", array_map("escapeshellarg", $opts))
.
If you are using a SSH1 connection, you can only execute one command at a time. If you are connecting to a Windows server (which this looks like), then you can't have two commands on a line.
Only for a BSD/Linux server you could use:
$ssh->exec("cmd1 ; cmd2");
精彩评论