简体   繁体   中英

Create a file in a different directory with SSH cat

I am trying to create a file automatically through PHP, but with the unix cat commands through SSH. I can create a file in the directory I am in, but I want to create a file in a different directory. This is the code that creates the file in the directory I am in:

$sPath = "/minecraft/servers/";
$sSavingCode = "server.properties";      
echo $ssh->exec("cat >".$sSavingCode." <<".$sPath."
    test");

This code gives this error, but it creates the file in the directory I am in:

bash: line 1: warning: here-document at line 0 delimited by end-of-file (wanted `/minecraft/servers/')

I just need a way to create the file in a different directory. Thanks

You used the path ( $sSavingCode ) as the delimiter for the heredoc statement. You should try the following statement. It uses the literal EOF as the delimiter for the heredoc section:

echo $ssh->exec("cat > $sPath/$sSavingCode <<EOF
    test
EOF
");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM