Having a good Continuous Integration setup can be one of the highlights of any developers daily grind. Regardless, it can be seen as almost pointless if your automated deployment setup still needs a physical person to upload the files to your server if it is offsite. Adding FTP/SFTP to your CI process is the solution to this.

A solution for FTP deployment is below, but for FTP there are two solutions – one using simple MSBUILD and external software, and the other using an additional MSBUILD task pack.

Solution #1 Simple directory upload

The first solution i will draw your attention to is for people simply wanting to copy all the build output to a remote host. In this instance, to keep things simple, i recommend using the MSBUILD community tasks pack. The reason for this is that it has a task called FtpUploadDirectoryContent that allows you to push a folder in one task. This can be great if you simply want to push a folders contents up to an FTP site and overwrite the content already there.

Install the above on both your local development machine (so that you can debug the build) and the build server.

Add the following task to your MSBUILD file. If you are using Web Deployment projects as per my original tutorial, simply make sure the task name is set to AfterBuild so that it fires after the build is complete. In this example i also use the default path $(OutputPath) that is part of the web deployment project – if you are using a simple MSBUILD script, then you will need to replace this with the path to your build output.

Solution #2 for More customised or complex deployments

Another solution that i would probably recommend more because it makes complicated deployments really easy is to use an MSBUILD EXEC task to fire a command line ftp client.

In my example i am going to use WinSCP as i find it the easiest to work with, and it supports all the main protocols ftp, ftps, sftp. The fact that it is FREE helps too :-) The reason i am such a fan is because it allows for scripting, allowing for complex deployments where many actions can take place. I will show you a simple deployment, but set it up in a way that makes adding extra automation really easy.

The log file FtpLog-YYYYMMDD.txt to write the output of the session to for later review

Things to consider now you have a sweet deployment strategy

Now that we have an automated system to deploy our sites by FTP, other things that you can consider doing by changing the FTP config script are:

Make sure that you are only building the Trunk of your source control, and do all development in a branch. This way when you successfully merge a range of upgrades that you’ve successfully tested, you only deploy tested changes.

Automatically push up an app_offline.htm file before you push the site up (blog post to come) and then delete it after your finished.

Potentially download any site side assets for archiving/backup (user uploaded photos)