faqts : Computers : Programming : Languages : Asp : ASP/VBScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

66 of 82 people (80%) answered Yes
Recently 5 of 10 people (50%) answered Yes


How can I retrieve a file from another webserver, and store it on my own webserver (using http)

Jul 4th, 2001 03:17
Acebone, Scott Fleming, http://hawkwynd.com

To retrieve a file from another webserver, we'll need to use the 
XMLHTTP object. To store the file on the server, we'll incorperate the 
Scripting.FileSystem object.
' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP") 
' Opens the connection to the remote server.
	xml.Open "GET", "http://www.usatoday.com/news/digest/nd1.htm", 
' Actually Sends the request and returns the data:
'Now that we've snatched the page from the server,
'Let's save it locally on our own server, we can make changes
'to the actual file before saving, by passing the xml.responseText
'to a string var, and then re-working that string before outputting it
' strBuffer=xml.ResponseText
'Example for stripping tags from the strNewBuffer
'MyArray = array("<ul>", "<li>","<hr>","</li>","</ul>","<FONT size=+2>")
' for each item in MyArray
'	strBuffer=replace(strBuffer, item, "")
' Next
'Display the re-vamped page to the browser
'Response.write strBuffer
'Here's how we write the RAW page to file on our server
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\inetpub\wwwroot\news\nd1.htm", True)
'Substitute xml.ResponseText with "strBuffer" to save the formatted 
'page to file instead of the RAW data from the server.
NOTE: For the curious, here's the PERL way of doing it under ASP

© 1999-2004 Synop Pty Ltd