batch file - Plink fails to run when executed from PHP in wamp, but works when executed manually
I need to access a Linux machine from Windows 7 via PHP.
For that I created simple bat (MyScript.bat
) script containing plink.
c:\wamp\www\abc\plink.exe [email protected] -pw l1c -C "df -h">11.txt
When I am executing the bat script, it's working fine, i.e. the output is written in file11.txt
But when I am accessing it from PHP, the11.txt
is created without data
echo exec('MyScript.bat');
Moreover, in browser, the script commands are displayed as text. I even tried to useprint_r
for the display.
"c:\wamp\www\abc\plink.exe [email protected] -pw l1c -C "df -h">11.txt
Answer
Solution:
Do not launch external tool for SSH.
PHP has native support for SSH.
Or use phpseclib:
See https://phpseclib.sourceforge.net/ssh/2.0/examples.html
Anyway, if you want to use Plink, redirect also the standard error output to debug your problem:
See How to redirect Windows cmd stdout and stderr to a single file?.
You are for sure missing the
to explicitly specify a fingerprint of the trusted hostkey.