Forum Moderators: coopster

Message Too Old, No Replies

PHP and FTP: Transferring entire directories

Surely this can be done - but I can't find out how

         

MatthewHSE

3:14 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to work out a script that will help me backup my website to another web server. The idea is to use PHP's FTP capabilities to transfer directories from one server to another. This allows me to get my slow DSL connection out of the backup picture, which will also vastly facilitate moving my site to another server if I should ever need to do that.

Anyway, I know how to transfer individual files using PHP FTP, but I don't know how to transfer whole directories. I've looked around the PHP documentation but haven't found anything that seemed to address this problem. In an ideal world I could just make a .tar.gz file of my site and transfer that; however, I don't have enough server space to do that and I'd rather have easier access to the backed up files anyway.

So, is there any way to use PHP's FTP capabilities to transfer directories from one server directly to another? And, if there is, will the file/directory permissions be maintained?

Any and all ideas welcome.

Thanks,

Matthew

Romeo

4:39 pm on Apr 8, 2005 (gmt 0)

10+ Year Member



Hi Matthew,

there are several ways to think of:

-- real ftp clients have mput and mget functions to pass a list of files -- don't know if the php-ftp has these.

-- you could make an own directory list of files and then run several single ftp put actions processing that list of files.

-- you could create a zip archive containing an entire directory structure and then ftp just that one zip file, which is very convenient, and additionally saves traffic bandwith.
If you can run shell commands, just do a `zip ...` out of php.
If you can't, then you may search for "php zip file creation class" or similar in Google ...

-- if you can run shell commands, you could try to call an rsync client to let rsync do that transfer stuff on entire directories, which works great and can do incremental transfers of newly changed files only.
It needs a running rsync server on the other end though. However, it does not matter, which end is the server and which the client, it would work both ways.

Have fun,
R.

leadegroot

9:16 pm on Apr 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the from-server, loop through the directories and files and ftp them one at a time.
Your host would probably appreciate the small delay you could easily build in, too
The code would probably be recursive, but thats ok because your directory structure probably isn't massive by computational standards.
I think [php.net...] would have most of the functions you require.