我需要备份站点的FTP。该站点托管在linux服务器上。问题是有一个包含超过5k个文件的文件夹。Linux不能显示超过4998个文件,所以我不能复制这些文件,因为服务器给我的文件不超过4998个。我不能删除这些文件来查看其他文件,因为站点实际上是在线的。出于同样的原因,我不能将这些文件移动到另一个目录中。
我能做什么?我正在尝试使用我不知道的shell...but ...我不确定是否使用此方法。
发布于 2015-10-07 22:34:02
我有我自己的答案
<?php
$rootPath = realpath('wp-content/uploads/2014/07');
// Initialize archive object
$zip = new ZipArchive();
$zip->open('dio.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();发布于 2015-10-07 21:54:41
您可以通过命令行来完成此操作,本指南中的shows you how。对于递归调用(子文件夹及其内容),似乎不推荐使用mget ( ftp命令),因此也可以使用wget,se this。
我也喜欢将这样的文件夹和许多文件压缩到一个文件夹中,以便在上传和下载时易于监督。使用
zip -r myfiles.zip myfiles这是一个guide for that too。
https://stackoverflow.com/questions/32993840
复制相似问题