Zvi Band Relationships are our most important asset.

Uploading CakePHP Code via Ant

U

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: , ,

6 comments

  • And thanks to Bennett for his CodeMarkup plugin.

    You’re welcome.
    Ant+FTP is a great idea for any website, not just Cake-based ones. I can’t imagine why I didn’t think of using Ant before, but I will use it in the future!

  • I’m starting to refine my own deployment process. I’ve been looking at Phing and Ant. I can’t use Capistrano because I’m still on shared hosting and it uses SSH.

    Anyway, the thing I dislike about Phing is that as of ver 2.3 it doesn’t come with an ftp task.

    Ant does, as you are demonstrating above, but aren’t there some issues with it such as:

    – doesn’t copy empty folders
    – cannot chmod files
    – cannot recursively delete hidden files

    Did you encounter/get around these issues?

    Thanks Zvi!

  • I see you share interesting content here, you can earn some additional money,
    your blog has big potential, for the monetizing method, just search in google – K2
    advices how to monetize a website

By Zvi
Zvi Band Relationships are our most important asset.

Zvi Band

Founder of Contactually.
I'm also passionate about growing the DC startup community, and I've founded Proudly Made in DC and the DC Tech Meetup.

Archives