PHP 通过 FTP 下载整个文件夹(递归)
我目前有一个非常大的网站,大小约为 5GB,包含 60,000 个文件。当前主机并没有做太多事情来帮助我将网站转移到新主机,我的想法是在新主机上制作一个简单的脚本,通过 FTP 传输到旧主机并下载整个 public_html 文件夹(递归地) ) 到新服务器。这是否可能,如果可以,是否有人可以分享任何链接以帮助解决此问题?非常感谢。
I currently have a very large site approximately 5gb in size with 60,000 files. The current host isn't doing much in the way of helping me transfer the site to the new host and what I was thinking was to make a simply script on my new host to FTP into the old host and download the entire public_html folder (recursively) to the new server. Is this possible and if so, does anyone have any links they could share to aid in this? Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能有更好的机制来完成您想做的事情。
首先,您可以使用
sftp
或scp
从一台主机到另一台主机吗?或
或
-P
可以轻松地重新启动停止/停止的下载。如果好的工具不起作用,请查看是否安装了
wget
:--continue
可以更轻松地重新启动停止/停止的下载。There are probably better mechanisms to do what you want to do.
First, can you use
sftp
orscp
from one host to the other?or
or
The
-P
makes it easy to restart a stalled/dead download.If good tools won't work, then see if
wget
is installed:The
--continue
makes it easier to restart a stalled/dead download.如果文件很多,我强烈建议您制作一个 .tar.gz 存档。
我不知道你对 php 有什么限制,但你可以在 php 中尝试这个:
然后你可以通过 http / ftp 或使用任何其他方法简单地下载 1 个 gzip 压缩存档。
If there are a lot of files, I strongly recomend you to make a .tar.gz archive.
I don't know what restrictions to php do you have but you can try this one in php:
Then you can simply download 1 single gziped archive via http / ftp or using any other method.
是的,您可以用纯 PHP 做到这一点!
我刚刚发布了 2 个新库来在 FTP / SFTP
递归复制远程 SFTP 服务器上的文件和文件夹(如果 local_path 以斜线结尾则上传文件夹内容,否则上传文件夹本身)
从远程FTP服务器下载目录(如果remote_dir以斜杠结尾则下载文件夹内容,否则下载文件夹本身)
$port = 22);
如果您想查看代码,您会看到递归函数的神奇之处;)
Yes you can do it in pure PHP !
I've just released 2 new libraries to do such things in FTP / SFTP
Recursively copy files and folders on remote SFTP server (If local_path ends with a slash upload folder content otherwise upload folder itself)
Download a directory from remote FTP server (If remote_dir ends with a slash download folder content otherwise download folder itself)
$port = 22);
If you want to look at the code, you will see recursive functions that do the magic ;)