The Coding Pad

Programming blog, discussions, tutorials, resources





Subscribe to get updates via email:

Delivered by FeedBurner

How to bulk transfer many files over FTP using PHP

Posted in February 2nd, 2008
Published in PHP

Have you ever wanted to transfer/upload many files using FTP, and sat there for hours watching the process and hoping that your FTP connection doesn’t time out?? Well, I have. This especially happens when I am uploading images, or a CMS. Well, I learned a little trick from Bo on how to use zipped files and PHP to make the file transfer process less painful.

This is how you do it:

Step 1: Zip everything you want copied.
Step 2: Upload the Zip file.
Step 3: Create a PHP file in the same directory called unzip.php and put this code in it:

<?php<br />
echo ‘</p>
<pre>’
;<br />
system(‘unzip your_file.zip’);<br />
?>

Step 4: Run the PHP file in a browser (you should see the unzip output).
Step 5: Remove the zip file and the unzip.php file from your server.
Step 6: Rejoice that you just saved yourself a hour of waiting!

Isn’t that nice?





Related Posts

6 Users Commented In " How to bulk transfer many files over FTP using PHP "

Subscribes to this post Comment RSS or TrackBack URL
Mark says,
2-4-2008 at 15:21:04 from 71.216.157.118    

That sounds more like using PHP to unzip an archive and not using PHP to transfer files via FTP like your title says.

Still, an interesting and unique solution. Thanks for the info.

mary says,
2-4-2008 at 17:07:13 from 71.226.213.144    

Mark,

Thanks for your comment. I see what you mean about the title though, it may have been a tad ambitious. The files are transferred in a zipped form via FTP and the unzipped using PHP on the server, reducing the time required to upload individual files, so the use of PHP is indirect here.

Thanks for your feedback.

george says,
2-5-2008 at 18:28:24 from 69.134.56.201    

Good tip, I’ve had to employ something similar esp with TinyMCE and such.

The problem I’ve run into is that the unzipped files aren’t considered to be owned by me, so I can’t move, delete, CHMOD, or rename them - kind of a problem.

The solution I’ve found is to use PCL Zip (http://www.phpconcept.net/pclzip/index.en.php), which allows you to CHMOD at the time of unzip, solving the problem.

Of course, your script is a lot smaller than PclZip’s 300K, so if it works - cheers!

mary says,
2-6-2008 at 11:30:54 from 71.226.213.144    

george,

Thanks for your comment and for the link. I’ll check it out. I recently used the PHP code above to extract a CMS after uploading the zip file to my hosting account. I didn’t notice any ownership issues. But I’ll ask Bo over at the Web Development Forums about it.

Another thing I generally do is to use the cPanel file manager extracting utility to unpack the archive, and that generally works well too.

thanks again george.

mary

CRaig Mullins says,
9-10-2008 at 14:43:23 from 76.126.232.73    

Looks like you need a primer on importing & exporting MySQL files. :)

Appears you didn’t import/export with the write character set.

Why your getting all the weird coding….

mary says,
9-10-2008 at 14:53:52 from 71.226.213.144    

Craig,

Not too sure what you’re referring to in your comment. What weird coding?

mary

Leave Your Reply Below

 Username

 Email Address

 Website

Sticky note: Please double check your comments before submit Please Note: The comment moderation maybe active so there is no need to resubmit your comment
 

 Subscribe in a reader

About The Site

It is what it is, my coding pad, a programming blog, yet another place for my restless mind.