![](/img/trans.png)
[英]How to upload a file from another server to another server using Curl?
[英]Upload a file from one server to another server
我必须位于两个不同的服务器上。 我想将文件www.myserver.com/thefile.txt上传到www.myotherserver.com/thesamefile.txt
尽管最简单的方法是将文件下载到我的计算机上然后上传,但是我想知道是否可以自动化并使服务器下载它
您可以让其他服务器访问您编写的URL www.myserver.com/thefile.txt,然后将其发布为www.myotherserver.com/thesamefile.txt?
如果两台服务器上都有ssh,请尝试使用scp。 `scp文件ssh_login @ host:/ path_to_download /
或使用php ftp_ *函数。
下面的代码片段应该工作。 只需确保$ read_file是第一台服务器上的url,而$ write_file是当前服务器上的位置,则它不应是url,而应是服务器上可以写入的绝对位置。
<?php
function copyFile($read_file, $write_file)
{
file_put_contents($write_file, file_get_contents($read_file));
}
?>
您有两种选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.