gpt4 book ai didi

php - PHP SSH Lib,回显到文件

转载 作者:行者123 更新时间:2023-12-02 14:38:38 25 4
gpt4 key购买 nike

我正在尝试创建一个PHP脚本,该脚本通过ssh在远程linux服务器上创建一个文件,并将文件内容回显到其中。

但是,我无法弄清楚如何正确,安全地编码/转义文件内容,以使内容不会被解释为命令。

我正在使用here的phpseclib。

我已经尝试过类似

echo $ssh->exec('sudo echo "' . escapeshellarg($newConfig) . '" > /etc/nginx/nginx.conf') . "\n";

但没有成功。

谢谢,

史蒂夫

最佳答案

escapeshellcmd呢?引用该vs escapeshellarg的描述:

escapeshellarg() adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument.



...和...

escapeshellcmd() escapes any characters in a string that might be used to trick a shell command into executing arbitrary commands. This function should be used to make sure that any data coming from user input is escaped before this data is passed to the exec() or system() functions, or to the backtick operator.

Following characters are preceded by a backslash: #&;`|*?~<>^()[]{}$\, \x0A and \xFF. ' and " are escaped only if they are not paired. In Windows, all these characters plus % are replaced by a space instead.

关于php - PHP SSH Lib,回显到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19638753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com