Automatic FTP
A few weeks ago I was looking for a way to automate downloading thousands of files from an ftp site, I figured using php would be sufficient since that is what the site I was working with used. I tried google and some of the better php sites but to no avail. So I found some code that was similar to what I wanted and tweaked (and by tweaked i mean almost completely rewrote) it to suit my needs. Now I'm not claiming to be a php genius (or any kind of genius for that matter) but I'm pretty impressed with what I came up with. In a nutshell what this code does is open up a mysql session and an ftp session to a remote server, then it runs a query in the mysql database to create an array for php to use. Then it loops through each item in the array and checks with the remote ftp server for the file, updates to that file (time based), and if the file matches a certain size to be ignored.
This turned out to be quite handy because by the time I was done I could modify the code slightly and search in different locations on the server as well as store the files on a different spot on my local machine.
To test this I ran a 13k item array through this script and it was quite flawless...took about 3.5 hours to run but that's still way faster than downloading by hand even if you include the time it took to write the script.
So I decided to share this script since i couldn't find one myself, feel free to modify it in any way, if you find a way to make it better, more efficient or even hyperthread the downloads I'd like to know so please send an email with the code. Just make sure something like ftpgrabber is in the subject line...otherwise you'll get deleted as spam er somethin'.
Print This Post