ASP
  Home arrow ASP arrow Page 4 - Getting Remote Files With ASP
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Getting Remote Files With ASP
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 58
    2005-08-09

    Table of Contents:
  • Getting Remote Files With ASP
  • The Concept
  • The Code Client Script Initialization
  • PerformUpdate() Explained
  • WriteFile() Explained

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Getting Remote Files With ASP - PerformUpdate() Explained


    (Page 4 of 5 )

    Within the PerformUpdate() subroutine, we send the request to the server, dumb the results into one big string variable, read that into an XML document, and parse the updates and messages.

    srvXmlHttp.open "GET", sServerURL & “?” & sGETData, false

    srvXmlHttp.send()

    sResponse = srvXmlHttp.responseText

    Set srvXmlHttp = Nothing

    If ( xmlDOMDocument.loadXML(sResponse) ) Then

    This if/then will fail in cases where the sServerURL is either unreachable or if the connection to the server times-out. The On Error Resume Next allows us to throw in an "else" statement, which is basically a way to hotwire ASP to allow us a try/catch block. 

    The first things we parse are the messages or text data passed from the server to the client. In our example, we check for three variables: MESSAGE, VERSION, and CODE. You can check for whatever you like. Just make sure that there are corresponding variables sending data in the server script –- you’ll see these three in the server code below. As I mentioned before, the config file that will store the current version and key, can be updated with the new version value once the update successfully completes.

    set objXMLList = xmlDOMDocument.getElementsByTagName("MESSAGE")

    If ( objXMLList.Length > 0 ) Then

          iMessage = Trim(objXMLList.item(0).text)

    End If

    set objXMLList = xmlDOMDocument.getElementsByTagName("VERSION")

    If ( objXMLList.Length > 0 ) Then

          sVersion = Trim(objXMLList.item(0).text)

    End If

    set objXMLList = xmlDOMDocument.getElementsByTagName("CODE")

    If ( objXMLList.Length > 0 ) Then

          sCode = Trim(objXMLList.item(0).text)

    End If

    After we get the text data, we begin getting the files. We loop through the XML looking for PATH nodes. For each PATH node, there is a corresponding TRANSFERFILE node. The PATH node contains path information that can be used to tell the client where to store the file. In our example, it simply holds the file name. If you like, you can add the full or relative path to retain the folder structure. The TRANSFERFILE node is the file itself.

    You’ll notice that within the loop, we do a check for a PATH with the word “UpdateScripts” in it (see the code below). This is how we are flagging our update script file. This is a file named UpdateScripts.asp on the server. Within that file is ASP code that will run on the client. The ExecuteGlobal() runs the actual code from this file. If the code that is sent from the server fails, an error is generated and trapped. If the file is not an update script, the system calls the WriteFile() subroutine with the name and type of the file to transfer.

    An error in the process will set the iMessage variable as E_UPDATESCRIPTFAILURE and exit the For loop. There you would want to alert the administrator that the update failed.

    If ( iMessage <> "" ) Then

      Set fsoFileObject = CreateObject("Scripting.FileSystemObject")

      Set objXMLList = xmlDOMDocument.getElementsByTagName("MALL23")

      For iX = 0 to (objXMLList.length - 1)

          sPath = ""

          For iY = 0 to ((objXMLList.item(iX).childNodes.length)-1)

    If ( objXMLList.item(iX).childNodes(iY).nodeName = "PATH" ) Then

          sPath = objXMLList.item(iX).childNodes(iY).text

    End If

    If ( sPath <> "" ) And

      ( objXMLList.item(iX).childNodes(iY).nodeName = " TRANSFERFILE" ) Then

    If ( InStr(sPath, "UpdateScripts") > 0 ) Then

          If ( Trim(objXMLList.item(iX).childNodes(iY).text) <> "" ) Then

                Response.Write(vbCrLf & _

    "<script language=""JavaScript"">" & _

    VbCrlf & VbCrlf & _ "document.UpdateForm.UpdateText.value = " & _ "'Beginning Update Script...';" & _

    VbCrlf & VbCrlf & _

    "</script>")

                ExecuteGlobal(objXMLList.item(iX).childNodes(iY).text)

                If ( Err.Number <> 0 ) Then

                      iMessage = E_UPDATESCRIPTFAILURE

                      Exit For

                Else

                      Response.Write(vbCrLf & _

    "<script language=""JavaScript"">" & _

    VbCrlf & VbCrlf & _ "document.UpdateForm.UpdateText.
    value = " & _ "'Finished Update Script';" & _

    VbCrlf & VbCrlf & _

    "</script>")

                End If

          End If

    Else

    If ( InStr(sPath, ".asp") <= 0 )

    And ( InStr(sPath, ".txt") <= 0 ) Then

                Call WriteFile(sPath,

    bjXMLList.item(iX).childNodes(iY).nodeTypedValue,

    C_BINARY)

          Else

                Call WriteFile(sPath,

    objXMLList.item(iX).childNodes(iY).text,

    C_TEXT)

          End If

    End If

    End If

    Next

    If ( iMessage = E_UPDATESCRIPTFAILURE ) Then

          ‘ alert admin here

          Exit For

    End If

    Next

    End If

                     

    Set xmlDOMDocument = Nothing

    Set fsoFileObject = Nothing

    End If

    More ASP Articles
    More By Justin Cook


       · Getting Remove Files is very nice article. But It will be so good if the screen...
     

    ASP ARTICLES

    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application
    - Easy Error Management





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT