Getting Remote Files With ASP
(Page 1 of 5 )
This article will show how to retrieve remote binary files, multiple files, and additional information with only ASP and XML. This is an incredibly powerful technique, and the implementation in this two part series will deal with automatically updating a deployed ASP web application.
A file is available to download for this article here.
Introduction
One of the most popular articles I’ve written was “Getting Remote Pages with ASP.” It seems that people found it as much of a lifesaver as I did, and were able to extend it in some very creative ways. This series of two articles deals with the best ones I’ve heard yet.
The programmer behind the popular e-commerce Web application Mall23
(http://www.mall23.com/store/Default.asp?vf=14) contacted me, asking me if I’d be interested in writing about his application. He told me he was able to extend the process of retrieving remote pages, to actually be able to retrieve remote binary files. This was his dilemma, to which you as a developer can no doubt relate:
“After developing several applications deployed to the public, I kept running into the same problem time and time again –- how to deploy updates. If you have ever used a third party ASP application, you know what I’m talking about. You install the software on your server and it sits, and sits. Six months later you find out that there have been three updates and tons of bug fixes. Problem is that no one told you about the updates, and now you have to figure out how to apply three different patches without destroying your site.”
“On the other hand, as a developer, it gets to be mind-boggling after deploying 30 different updates. Which customer has which version? Which client has modified what in which version? In the past, I’ve always added a version identifier to my software and had my patches loop through and update to the current version. Nice, but doesn’t solve the problem of making it transparent for the site owner. Many times I would find small bugs (like a misspelled word), and I’d have to sit on it until I had enough to justify my creating a whole new deployment, announcing it to the public, and getting them to spend the time to download and install it. What a pain. For everyone.”
It seems that major software developers had already solved this issue for client-based applications, devising a system call “auto-update.” Unfortunately, ASP has no inherent way of transferring files, let alone binary files!
My previous article described how to use a free, Microsoft-provided XMLHTTP object to retrieve Web pages as XML, and save them locally. While this works great for the Web, XML, and even text, it seems it just can’t be done for binary files.
Well if there’s one phrase that most developers refuse to utter or believe, “it can’t be done” is it! With no small amount of programming ingenuity -- and one more free tool provided by Microsoft -- a clean (and extensible) solution was created.
Microsoft has built a Base64-to-XML converter, called Msxml2.DOMDocument. We’ll use it to encode and decode the files, XMLHTTP to transmit the files, and finally ADO to save the files.
Before We Proceed This article will make use of the MSXML2.ServerXMLHTTP object. Make sure you have this installed on the machine from which the script is running. You can find the Microsoft XML parser 3.0 sp4 here: http://www.microsoft.com/downloads/details.aspx?FamilyId=C0F86022-
2D4C-4162-8FB8-66BFC12F32B0&displaylang=en
Next: The Concept >>
More ASP Articles
More By Justin Cook