Use XMLHTTP and AdoDb.Stream to get remote files and save them to your local

zhaozj2021-02-16  50

<% '******************************************************* **************************** 'PageName: getRemoteFiles.asp'Function: Download The Files To Server'Author: xiaotian'Last Modified AT: 2003-3-19 '*************************************************** ****************************************

'Get Remote Files and save to local Function GetRemotefiels (RemotePath, LocalPath, FileName) DIM STRBODYDIM FILEPATH

ON Error ResMe next

'Save StrBody = getBody (RemotePath)' acquired saved file name if right (localpath, 1) <> "/" Then localpath = localpath & "filepath = localpath & getFileName (remotepath, filename) 'Save File If SaveTofile (strbody, filepath) = true and err.number = 0 Then getRemoteFiles = true else getremotefiles = false endiff

END FUNCTION

'Remote Get Content Function GetBody (URL) DIM RETRIEVAL' Establishing XMLHTTP Object Set Retrieval = CreateObject ("Microsoft.xmlhttp") with retrieval .Open "Get", URL, FALSE, "," "" "" With set retrieval = Nothing end function

'Recombination file name Function GetFileName (RemotePath, FileName) Dim arrTmpDim strFileExt arrTmp = Split (RemotePath, ".") StrFileExt = arrTmp (UBound (arrTmp)) GetFileName = FileName & "." & StrFileExtEnd Function

'Save the flow content as file Function Savetofile (Stream, FilePath) DIM OBJSTREAM

ON Error ResMe next

'Create ADODB.Stream object must be above ADO 2.5 Set objStream = Server.CreateObject ( "ADODB.Stream") objStream.Type = 1' objStream.Open objstream.write Stream objstream.SaveToFile FilePath opened in binary mode, 2 objstream .Close () 'Close object, release resource set objstream = Nothingif Err.Number <> 0 Then Savetofile = false else savetofile = true end ingnd function%>

转载请注明原文地址:https://www.9cbs.com/read-24314.html

New Post(0)