|
|||
|
Server To Server File Transfer
This script shows how to use XMLHTTP to transfer a file (or list of files)
from a remote server (or domain) to the server that this script is running on.
This example also checks to see if the files exists. If it does, it deletes the
existing file then creates the new file. Otherwise, it will not create the new file.
Here is the ASP code for this script:
<% 'Create xmlHTTP Object Set xmlHTTP = CreateObject("MSXML2.ServerXMLHTTP") 'Save To Folder on this server SaveToFldr = Server.MapPath("SomeFolder") 'Create a list of files to retrieve TheURLS = "http://www.ThisDomain.com/SomeFile1.jpg|" & _ "http://www.ThatDomain.com/SomeFile2.xls|" & _ "http://www.SomeOtherDomain.com/SomeFile3.pdf" 'Create File List Array UrlArr = Split(TheURLs,"|") 'Cycle through File List For x = 0 To UBound(UrlArr) 'Save As File Name SaveAsFile = SaveToFldr & "/" Right(UrlArr(x),Len(UrlArr(x))-InstrRev(UrlArr(x),"/")) 'Get File xmlHTTP.open "GET", UrlArr(x), false 'Send Request xmlHTTP.send() 'Check to see if file is available If xmlHttp.Status = "200" AND xmlHttp.Status <> "404" then 'Create Datastream object to save the file set DataStream = CreateObject("ADODB.Stream") 'Open Datastream DataStream.Open 'Set type to binary DataStream.Type = 1 'Create bianry datastream of the file DataStream.Write xmlHTTP.ResponseBody DataStream.Position = 0 'Set the File System Object, so we can check to see if it already exists. set FSO = Createobject("Scripting.FileSystemObject") 'If the file already exists, delete it if FSO.FileExists(SaveAsFile) then Fso.DeleteFile SaveAsFile End If set FSO = Nothing 'Write the file to the location on the server DataStream.SaveToFile SaveAsFile 'Close Datastream DataStream.Close 'Delete Datastream object set DataStream = Nothing End If Next 'Delete xmlHTTP Object Set xmlHTTP = Nothing %> |