如何使用php-ssh-exec将多行内容写入任何linux文件系统


How to write multiple line content to any linux filesystem using php ssh exec?

假设有一个包含内容的文件(test.txt)。

testing php data
employee data
country data

我想在远程linux机器的/tmp目录中编写此内容。我正在使用以下代码

 // $con contains all content of the text.txt file
 $con = file_get_contents("C:/wamp/www/test.txt");
 // $ssh is the sshobject for the remote machine
 $ssh->exec('echo "$con" > /tmp/text1.txt');

它在远程机器上创建一个空文件。我应该使用什么来复制远程机器上的内容?

检查您的报价。

$ssh->exec('echo "'.$con.'" > /tmp/text1.txt');

$con不会用一句话来解析。

您应该编写以下代码

 // $con contains all content of the text.txt file
 $con = file_get_contents("C:/wamp/www/test.txt");
 // $ssh is the sshobject for the remote machine
 $ssh->exec("echo '{$con}' > /tmp/text1.txt");