Workaround for FTP Authorization Rules being deleted on sync

NOTE: This is a cross-post from bilalaslam.com. Interested in learning more about Web Deploy? Follow us on Twitter @wdeploy

I had a customer contact me with an issue: FTP Authorization Rules for a site were being deleted after sync.

He has two IIS 7 servers (call them source-server _and _destination-server), and there’s an FTP website called “MyFtpSite” on both servers. Destination-server has some extra settings for MyFtpSite, specifically FTP Authorization Rules, which are not present on source-server. The customer ran this command on source-server:

<div><span style="color: #000000;">msdeploy</span><span style="color: #000000;">.</span><span style="color: #000000;">exe -verb</span><span style="color: #800000;">:sync</span><span style="color: #000000;"> -source</span><span style="color: #800000;">:webServer</span><span style="color: #000000;"> -dest</span><span style="color: #800000;">:auto</span><span style="color: #000000;">,</span><span style="color: #000000;">computername</span><span style="color: #000000;">=</span><span style="color: #000000;">destination-server -skip</span><span style="color: #800000;">:website</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">MyFtpSite</span><span style="color: #000000;">"</span></div>

msdeploy.exe command line provides nice syntatic sugar, –skip:website= for skipping a whole website. Once this command ran, he noticed that MyFtpSite’s content was untouched but its FTP Authorization Rules were deleted. What was going on?

Under the covers, –skip:website= is the same as doing –skip:objectName=. This will skip all objects named yourWebsite. However, I looked at _destination-server’s _applicationHost.config, and voila, FTP Authorization Rules were being declared in a tag. It turns out there’s a bug in Web Deploy v1.1. where the –skip:website syntactic sugar does not skip tags and, as a result, it’s an object the source does not see, so it’s deleted:

<div><span style="color: #0000FF;"><</span><span style="color: #800000;">location </span><span style="color: #FF0000;">path</span><span style="color: #0000FF;">="MyFtpSite"</span><span style="color: #0000FF;">></span><span style="color: #000000;">
        </span><span style="color: #0000FF;"><</span><span style="color: #800000;">system.ftpServer</span><span style="color: #0000FF;">></span><span style="color: #000000;">
            </span><span style="color: #0000FF;"><</span><span style="color: #800000;">security</span><span style="color: #0000FF;">></span><span style="color: #000000;">
                </span><span style="color: #0000FF;"><</span><span style="color: #800000;">authorization</span><span style="color: #0000FF;">></span><span style="color: #000000;">
                    </span><span style="color: #0000FF;"><</span><span style="color: #800000;">add </span><span style="color: #FF0000;">accessType</span><span style="color: #0000FF;">="Allow"</span><span style="color: #FF0000;"> users</span><span style="color: #0000FF;">="*"</span><span style="color: #FF0000;"> permissions</span><span style="color: #0000FF;">="Read, Write"</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/></span><span style="color: #000000;">
                </span><span style="color: #0000FF;"></</span><span style="color: #800000;">authorization</span><span style="color: #0000FF;">></span><span style="color: #000000;">
            </span><span style="color: #0000FF;"></</span><span style="color: #800000;">security</span><span style="color: #0000FF;">></span><span style="color: #000000;">
        </span><span style="color: #0000FF;"></</span><span style="color: #800000;">system.ftpServer</span><span style="color: #0000FF;">></span><span style="color: #000000;">
    </span><span style="color: #0000FF;"></</span><span style="color: #800000;">location</span><span style="color: #0000FF;">></span></div>

What’s the workaround? You have to have a separate skip for the tag:

<div><span style="color: #000000;">msdeploy</span><span style="color: #000000;">.</span><span style="color: #000000;">exe -verb</span><span style="color: #800000;">:sycn</span><span style="color: #000000;"> -source</span><span style="color: #800000;">:webServer</span><span style="color: #000000;"> -dest</span><span style="color: #800000;">:auto</span><span style="color: #000000;">,</span><span style="color: #000000;">computername</span><span style="color: #000000;">=</span><span style="color: #000000;">destination-server -skip</span><span style="color: #800000;">:website</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">MyFtpSite</span><span style="color: #000000;">"</span><span style="color: #000000;"> -skip</span><span style="color: #800000;">:xPath</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">//section[@name='system.ftpServer/security/authorization']</span><span style="color: #000000;">"</span></div>

Note: I should really make this skip a little tighter, because it will skip syncing system.ftpServer/security/authorization sections for ANY website. But you get the idea … Smile