I first looked into using an FTP library like: http://www.codeproject.com/KB/IP/ftplib.aspx but soon realized that any hand rolled application would need to be robust enough to handle connection problems and update failures etc. It was then that I realized I already owned a tool that could with a little effort take care of the job.
WS_FTP Professional
A simple example:
CONNECT "My Sites!Mysitename.info"
LCD “C://NewFiles”
CD “bin”
RDEL “*”
RPUT “*”
CLOSE
Here the script simply connects to a site in the My Sites group (think of the exclamation mark as a /), navigates to the folder locally where the new files are located, navigates to the bin folder of the remote site, deletes the contents, uploads the new files and finally closes the connection.
This is a simple example but you can target specific files and navigate folders during the same session, you can also download files. Even so writing a 100 of these for a single update is still a little annoying and sadly there is no for each loop to iterate through the sites in the "My Sites Group" part in the scripting language. What worked for me was to write a small Winforms app which helps me write the scripts using placeholders. This application reads the site names from a small data store and uses syntax like:
CONNECT “#SiteName#”
LCD “#LocalSiteFolder#”
DEL “web.config”
PUT “web.config”
CLOSE
When I click the go button in the Winform, the application generates a script for each of the sites, replacing the placeholders (e.g. #SiteName#) with the appropriate text. This works well too if, as in my scenario, the web.config file for each site has site specific settings, so in the example above I am able to target the folder for that specific site (which contains site specific files) and specify a file in it (this also works well for CSS files as each site has it's own theme).
All I need do is save the script and schedule it to run or simply paste it directly into the WS_FTP scripting utility and let it go about it's business. The WS_FTP Scripting Tool also has a log panel, so you can see if an update has failed for whatever reason.
As you can see with a little effort and the right tool you can turn a maintenance nightmare into a relatively painless exercise.












1 comments:
Trés useful. Thanks a lot.
Post a Comment