简体   繁体   English

使用PHP通过FTP上载文件夹

[英]Upload a folder via FTP using PHP

Our website currently backs up every night to a seperate server that we have which is fine, but when we go to dowload the files the next day it take's a long time to download the files (usually around 36,000+ images). 目前,我们的网站每天晚上都会备份到一台单独的服务器上,这很好,但是第二天我们下载文件时,下载文件需要很长时间(通常约36,000多个图像)。 Downloading this the following day takes quite some time and affects the speeds of everyone else using our network so ideally we would try and do this in the middle of the night - except there's no-one here to do it. 第二天下载此文件会花费相当长的时间,并且会影响使用我们网络的其他所有人的速度,因此理想情况下,我们将在深夜尝试这样做-除非这里没有人这样做。

The server that the backup is on is running Cpanel which appears to make it fairly simple to run a PHP file as a Cron job. 备份所在的服务器正在运行Cpanel,这似乎使得将PHP文件作为Cron作业运行起来相当简单。

I'm assuming the following, feel free to tell me I'm wrong. 我假设以下情况,请随时告诉我我错了。

1) The server the backup is on runs Cpanel. 1)备份所在的服务器运行Cpanel。 It appears that it shouldn't be too difficult to set up a PHP script to run as a Cron job in the middle of the night. 看起来在半夜设置PHP脚本作为Cron作业运行并不难。

2) We could deploy a PHP script utilizing the FTP functions to connect to another server and start the backup of these files using this cron job. 2)我们可以使用FTP功能部署PHP脚本以连接到另一台服务器,并使用此cron作业开始备份这些文件。

3) We are running Xampp on a windows platform. 3)我们在Windows平台上运行Xampp。 It has Filezilla as part of it so I'm assuming it should be able to accept incoming FTP connections. 它包含Filezilla作为其一部分,因此我假设它应该能够接受传入的FTP连接。

4) Overall - we could deploy a script on the backup server that would run every night and send the files back to my local computer running Xampp. 4)总的来说-我们可以在备份服务器上部署一个脚本,该脚本每天晚上运行,并将文件发送回运行Xampp的本地计算机。

So that's what I'm guessing. 这就是我的猜测。 I'm getting stuck at the first hurdle though. 不过,我遇到了第一个障碍。 I've tried to create a script that runs on our local computer and sends a specified folder to the backup server when it executes, but all I seem to be able to find is scripts relating to single files. 我试图创建一个在本地计算机上运行的脚本,并在执行时将指定的文件夹发送到备份服务器,但是我似乎只能找到与单个文件相关的脚本。 Although I've some experience of PHP, I haven't touched upon the FTP functions before which are giving me some problems. 尽管我有一些PHP的经验,但是在使用FTP函数之前,我还没有碰到过一些问题。 I've tried the other examples here on stack overflow with no success :( 我已经在堆栈溢出尝试了其他示例,但没有成功:(

I'm just looking for the most simplistic form of a script that can transfer upload a folder to a remote IP. 我只是在寻找脚本的最简单形式,可以将上载文件夹转移到远程IP。 Any help would be appreciated. 任何帮助,将不胜感激。

There is a fair amount of overhead involved in transferring a bunch of small files over FTP. 通过FTP传输一堆小文件涉及相当多的开销。 Ive seen jobs take 5x as long, over a local network. 我见过,在本地网络上作业的时间是原来的5倍。 It is by far easier to pack the files in something like a zip and send them in one large file. 到目前为止,将文件打包成类似zip的格式并将其发送到一个大文件中要容易得多。

you can use exec() to run zip from the command line (or whatever compression tool you prefer). 您可以使用exec()从命令行(或您喜欢的任何压缩工具exec()运行zip After that, you can send it over ftp pretty quickly (you said you found methods for transferring 1 file). 之后,您可以非常快速地通过ftp发送它(您说找到了传输1个文件的方法)。 For backup purposes, having the files zipped would probably makes things easier to handle, but if you need them unzipped you can setup a job on the other machine to unpack the file. 出于备份目的,压缩文件可能会使处理起来更容易,但是如果需要将其解压缩,则可以在另一台计算机上设置作业以解压缩文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM