One of the tasks that annoys me most is moving my code to our production web servers. It's a royal pain the ass to fire up SmartFTP/FileZilla/whatever, navigate your folders, connect, and so on, especially if you are frequently publishing. On top of this, manual FTP uploading can also be error prone. I'd like a nickel for every time I've overwritten production-specific config files with development copies.
The easiest way I could think to publish changes is to simply push a freaking button. So, a month or two back I found a simply FTP upload script. The script (I can't remember where I got it) often worked, but once my projects started growing in size, it would often time out and only a portion of my code would make it up. I figured the best solution would be to write my upload script that cycled through my project files and used a remote script to upload them one by one rather than in one big session. Sure, it's slower, but hey, it works and all I ever have to do is click one freaking button.
Below are the spoils of my endeavor and some commenting:
Grab the code here.
ftp_tools.php: Utility functions. Nothing to change here. echo_jsarray() recursively browses a directory and prints a Javascript object containing information about the files in it.
ftp_upload.php: The script that actually handles uploading a file passed to it. Here you want to change the $ACCOUNTS variable to hold the FTP login info for your various projects. Also change the $FTPADDR string to hold your server's address.
SampleProject.migrate.php: The script that handles uploading your files, one by one. There are some variables up at the top you'll want to change such as file exceptions and the directory you want to upload from. In UploadFile() you'll also want to define the account you want to use.
Setup: On our production FTP server, I have an account for each project. The root directory of each of these accounts is the project's root folder. Thus, I simply upload to the root folder for every project. Dump all of these files into a folder on your test server or something, grab jQuery 1.2.6 (minified) and add it to the mix, and you should be good to go.
It's a pretty rough, environment-specific way to do this, but it should be no problem to adapt to your own development environment. Bonus points: Figure out which files have been changed and which have not, and upload only the changed files. Add some error handling for when files fail to upload mid-stream.

Recent Comments