phptelnet 与 phpseclib

发布于 2024-09-16 03:18:20 字数 721 浏览 2 评论 0原文

我正在尝试从 php 连接 unix 服务器并执行 .exe (C 语言)。早些时候我使用 phptelnet 来实现此目的,但现在由于安全问题我需要转向 phpseclib。我使用phptelnet时成功率是100%。我可以运行一些外部程序,例如“C”程序,并将参数作为 php 脚本中的输入。在 phptelnet 中我使用

$telnet->DoCommand('cd public_html');
$telnet->DoCommand('cd abc');
$telnet->DoCommand('demo.exe');
$telnet->DoCommand("$inputs", $result);
echo $result;

这非常完美。但现在我正在使用 phpseclib。我可以通过 ssh 连接到 unix 服务器并执行程序,其中输入被硬编码在程序中。我正在使用

echo $ssh->exec('./demo.exe');

现在的问题是如何向程序提供输入。如何使用 exec() 接受参数作为输入。例如,demo.exe 是一个将两个数字相加的程序。所以我可以说

 echo $ssh->exec("./demo.exe, '10 20'");

另外我如何使用 exec() 在一次执行中执行多个代码行。我有点困惑。非常感谢对此的任何投入。

提前致谢。

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 with 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-09-23 03:18:20

当您使用的命令有多个选项时:

 $ssh->exec("./demo.exe '10' '20'");

省略逗号,并将每个参数括起来。或者使用 $opts = implode(" ", array_map("escapeshellarg", $opts)) 转换列表。

如果您使用 SSH1 连接,则一次只能执行一个命令。如果您要连接到 Windows 服务器(看起来像这样),那么一行上不能有两个命令。

仅对于 BSD/Linux 服务器,您可以使用:

 $ssh->exec("cmd1 ; cmd2");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文