This is one of these über-geek entry about shell scripting that will only be pertinent to a tiny fraction of this blog’s readership. I just wanted to consign this to the biggest technical library in the world.
Silly as it is, up until recently, I was manually packaging and uploading upgrades for all my WP plugins. Zipping (after removing OS X invisible breadcrumb files if I felt like it), getting my ftp client fired up, browsing to the right location, uploading… The whole process never took more than a minute or so, but was becoming painstakingly repetitive. Especially when you notice you missed a small typo somewhere and have to redo it again 10 seconds later.
I knew there were a thousands way to automate this with a shell script or otherwise, just never bothered… And I probably should have.
This is a typical example of how a small effort could save you a lot of efforts afterward: laziness is a quality in software development, provided it’s used with some foresight.
Anyway, the script turned out to be 4 line long, took 5 minutes to write, and I’m sure it could be of some use for people out there who regularly have to zip and upload a package on a specific website:
zip -r your_package.zip your_package/ -x \*/.\*
ftp -u ftp://ftp_username:ftp_password@ftp_server/path/to/destination/ftp/dir/ your_package.zip
Replace text in bold with your own values and save as file.
This will work with most Unix shells I can think of, provided you have
ftp installed (OS X does, by default).
If you are using OS X, add the .command extension to the script name and you will be able to run it by simply double-clicking it.
Note: don’t forget to make your script executable (run
chmod a+x your_script.command).
Note 2: in the script above, mind the space (not a carriage return) between the path and the zip file.