複製遠程文件,我想用PHP執行命令(rsync的)從遠程服務器複製文件夾和文件到本地文件夾。使用rsync在PHP
這是我在PHP寫的代碼。在SSH(本地終端和遠程putty.exe
)中執行WORKS命令,正確複製文件夾和文件。
但它不能在PHP工作。我能做什麼?你知道更好的(安全/最佳)方法嗎?
exec("echo superuserpassword | sudo -S sshpass -p 'sshremoteserverpassword' rsync -rvogp --chmod=ugo=rwX --chown=ftpuser:ftpuser -e ssh [email protected]:/path/files/folder /opt/lampp/htdocs/dowloadedfiles/", $output, $exit_code);
編輯: 我讀了這個guide創建我的服務器和我的本地機器之間的聯繫。現在
我可以在遠程機器上使用ssh登錄不需要密碼。
我改變了我的命令:
rsync -crahvP --chmod=ugo=rwX --chown=ftpuser:ftpuser remote.com:/path/to/remote/files /path/to/local/files/
該命令也工作在終端,但是當我EXEC命令PHP發送,再次失敗,但我得到了另一種不同的錯誤:127
正如MarcoS在他的回答中所說的,我檢查了error_log。
的消息是這樣的:
ssh: relocation error: ssh: symbol EVP_des_cbc, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: remote command not found (code 127) at io.c(226) [Receiver=3.1.1]
什麼「不起作用」?你有錯誤嗎? – WillardSolutions
該命令不會複製文件和文件夾。該2個變量進行這樣的: $輸出= 1個 $ exit_code = 1 –