我有一个阵列或超过1,000个文件需要从我的服务器下载到我的本地PC。
我需要让它为每个文件复制相同的文件/文件夹结构。
以下是文件的示例列表:
/lib/Zend/EventManager/Filter/FilterIterator.php
/lib/Zend/EventManager/config.php
/lib/Zend/Text/Figlet/themes.php
/lib/Zend/Gdata/Analytics/DataEntry.php
/lib/Zend/Gdata/Analytics/AccountQuery.php
/lib/Zend/Gdata/Calendar/files.php
/lib/Zend/Gdata/Query.php
/lib/Zend/Gdata/Gbase/Feed.php
/lib/Zend/Gdata/Photos.php
/lib/Zend/Gdata/Photos/AlbumFeed.php
/lib/Zend/Gdata/Media/Extension/press.php
/lib/Zend/Gdata/Media/file.php
/lib/Zend/Gdata/Extension/RecurrenceException.php
/lib/Zend/Gdata/Extension/Comments.php
/lib/Zend/Gdata/Extension/Recurrence.php
/lib/Zend/Gdata/Extension/Rating.php
要创建文件夹,使用FTP导航到它们,然后下载它们将花费我一整天!我怎么能用PHP做到这一点?
这些文件无法在浏览器中使用URL访问,因此我必须使用文件路径。
更新
这是我到目前为止尝试使用PHP ZipArchive ...
files.txt
测试文件以测试我需要的文件样本。最终结果将超过1,000个文件
lib/Zend/EventManager/Filter/FilterIterator.php
lib/Zend/EventManager/config.php
lib/Zend/Text/Figlet/themes.php
lib/Zend/Gdata/Analytics/DataEntry.php
lib/Zend/Gdata/Analytics/AccountQuery.php
lib/Zend/Gdata/Calendar/files.php
lib/Zend/Gdata/Query.php
lib/Zend/Gdata/Gbase/Feed.php
lib/Zend/Gdata/Photos.php
lib/Zend/Gdata/Photos/AlbumFeed.php
lib/Zend/Gdata/Media/Extension/press.php
lib/Zend/Gdata/Media/file.php
lib/Zend/Gdata/Extension/RecurrenceException.php
lib/Zend/Gdata/Extension/Comments.php
lib/Zend/Gdata/Extension/Recurrence.php
lib/Zend/Gdata/Extension/Rating.php
lib/Zend/Gdata/Books/VolumeQuery.php
lib/Zend/Gdata/Books/VolumeFeed.php
lib/Zend/Gdata/Exif/themes.php
lib/Zend/Gdata/MimeBodyString.php
lib/Zend/Gdata/HttpAdapterStreamingProxy.php
lib/Zend/Gdata/Spreadsheets/Extension/test.php
lib/Zend/Gdata/Spreadsheets/ListEntry.php
lib/Zend/Gdata/Gapps/Query.php
lib/Zend/Gdata/Gapps/GroupQuery.php
lib/Zend/Gdata/Gapps/EmailListRecipientQuery.php
lib/Zend/Gdata/Gapps/Error.php
lib/Zend/Gdata/Gapps/OwnerFeed.php
lib/Zend/Gdata/Gapps/alias.php
lib/Zend/Gdata/Gapps/MemberQuery.php
lib/Zend/Gdata/Gapps/EmailListQuery.php
lib/Zend/Gdata/Gapps/NicknameFeed.php
lib/Zend/Gdata/Exif.php
lib/Zend/Gdata/App/LoggingHttpClientAdapterSocket.php
lib/Zend/Gdata/App/Extension.php
lib/Zend/Gdata/App/MediaEntry.php
lib/Zend/Gdata/App/FeedEntryParent.php
lib/Zend/Gdata/App/AuthException.php
download.php
$zip = new ZipArchive();
$filename = "./test112.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}else{
echo 'zip good';
}
//$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
//$zip->addFile("lib/Zend/files2.txt" ,"lib/Zend/EventManager/test.php" );
// list of files to download
$lines = file('files.txt');
// Loop through our array of files from the files.txt file
foreach ($lines as $line_num =>$file) {
//echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($file) . "<br />\n";
// Add files to Zip file incliuding folder structure
$zip->addFile($file,$file);
echo $file;
}
// show number of files in new zip file and close zip archive
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
结果
这会创建我的zip文件,但不会添加所有文件,而只会将我的files数组中的最后一个文件添加到zip存档中!在此示例中为lib/Zend/Gdata/App/AuthException.php
答案 0 :(得分:1)
由于您具有SSH访问权限,因此您只需在服务器上运行它:
# Change '*.php' to whatever you want to retrieve:
find . -name '*.php' -print | zip archive.zip -@
然后你可以通过scp或ftp获取文件archive.zip。