Uploading CakePHP Code via Ant

I’ve been doing developing in CakePHP, which is a pretty awesome rapid development framework, that tries (with 90% success) to give die-hard PHP developers a fast way to build up applications (similar to Ruby on Rails). I’ve only gotten my feet wet with it so far, but I can see it really going places.

One thing that always annoys me is developing code on my own machine, and transferring it onto a development/live server to see it in action. Previously I was doing all of my development in Dreamweaver, which has the ability to automatically upload files as you save each one. I got fed up with Dreamweaver, and switched to EasyEclipse (the main Eclipse bundled with useful plugins), and thought I would forever be stuck with Alt+Tab-ing to an FTP client, copying, pasting, waiting, cursing. Then I was looking through a CakePHP Bakery post, and found that Apache Ant can be used to FTP files. After seeing Francis’ script and doing some more stumbling, I hacked up my perfect build.xml file.



	




	
		
	

	
		
                        password="${ftpPassword}" timediffauto="true"
                        remotedir="${remoteDir}/app" action="send"
                         verbose="yes" passive="yes" depends="yes">
			
			
		
	

	
		
                        password="${ftpPassword}" timediffauto="true"
                        remotedir="${remoteDir}" action="send"
                        verbose="yes" passive="yes">
			
			
		
	

From Eclipse, simply run the publishAll target one time – this copies all the CakePHP goodness onto your server. From then on, just run the startPublish target whenever you want to test something out. That will only copy the files in /app (this is the directory that all your custom code/configuration lives) that have changed up onto your server. It only takes me 5 minutes to run the first command, and ~1 minute to re-sync the files.

Note: You’ll need to add a couple libraries into ant in order for it to work. Brandon Harper’s post was very helpful.

…And thanks to Bennett for his CodeMarkup plugin.

Technorati Tags: , ,