将网站全部下载下来的ASP代码

Description:

A script that downloads files from a remote web server to a local mirror site (you can use it for just downloading files to anywhere you want...)

Script:

'*************************************************************************************************
' Download.vbs - Download files from the internet to local mirror servers
' Created by Martin77 (version 1.0)
'*************************************************************************************************
Option Explicit
On Error Resume Next

Dim LogPath, SourceURL, TargetPath, Files2Download

'*************************************************************************************************
'            Edit these variables only!
'*************************************************************************************************
            'Where to save the log file:
            LogPath = "C:/Inetpub/wwwroot/Logs/"

            'From where download the files:
            SourceURL = "http://www.somesite.com/rootfolder/otherfolder/"
                            
            'Where to save the downloaded files:
            TargetPath = "C:/Inetpub/wwwroot/LocalSite/"
                            
            'What files to download (separated by ','):
            Files2Download = "file1.txt,file2.exe,file3.zip"

'*************************************************************************************************
    Main 'Run the main process
'*************************************************************************************************
'Main process:
Sub Main
    Dim strOutputFile, strErrCode, strOutPut, i
    Dim objArgs, objFSO, objOutputFile, objHTTP
    Dim arrFiles2Download
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    arrFiles2Download = Split(Files2Download,",")
    strOutputFile = LogPath & "Download-Log-" & Replace(Date,"/","-") & ".log"

    'Parse Arguments (from App. Center URL Health Monitor):
    Set objArgs = Wscript.Arguments
    For i = 0 To objArgs.count - 1
        strErrCode = strErrCode & objArgs(i) & " "
    Next
    Set objArgs = Nothing
    strOutPut = Now & " - " & strErrCode

    'Download files:
    For i = 0 To Ubound(arrFiles2Download)
        If SaveWebBinary(SourceURL & arrFiles2Download(i), TargetPath & arrFiles2Download(i)) Then
            'Download OK:
            strOutPut = strOutPut & vbCrLf & Now & " - Downloaded file: " & arrFiles2Download(i)
        Else
            'Download Error
            strOutPut = strOutPut & vbCrLf & Now & " - Error downloading file: " & arrFiles2Download(i)
        End If
    Next
    'Write LogFile:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objOutputFile = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
    objOutputFile.Write "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" & vbCrLf
    objOutputFile.Write strOutPut & vbCrLf
    objOutputFile.Write "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" & vbCrLf
    objOutputFile.Close
    Set objFSO = Nothing
    Set objOutputFile = Nothing
End Sub
'*************************************************************************************************
'Download the file from %strUrl% to %strFile% - returns True / False
Function SaveWebBinary(strUrl, strFile) 'As Boolean
    Const adTypeBinary = 1
    Const adSaveCreateOverWrite = 2
    Const ForWriting = 2
    Dim web, varByteArray, strData, strBuffer, lngCounter, ado
    Err.Clear
    Set web = Nothing
    Set web = CreateObject("WinHttp.WinHttpRequest.5.1")
    If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest")
    If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP")
    If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP")
    web.Open "GET", strURL, False
    web.Send
    If Err.Number <> 0 Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    If web.Status <> "200" Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    varByteArray = web.ResponseBody
    Set web = Nothing
    
    'Save the file
    On Error Resume Next
    Set ado = Nothing
    Set ado = CreateObject("ADODB.Stream")
    If ado Is Nothing Then
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(strFile, ForWriting, True)
        strData = ""
        strBuffer = ""
        For lngCounter = 0 to UBound(varByteArray)
            ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
        Next
        ts.Close
    Else
        ado.Type = adTypeBinary
        ado.Open
        ado.Write varByteArray
        ado.SaveToFile strFile, adSaveCreateOverWrite
        ado.Close
    End If
    SaveWebBinary = True
End Function
'*************************************************************************************************

Keywords: Dwonload, Savewebbinary, Winhttp.winhttprequest.5.1, Winhttp.winhttprequest, Msxml2.serverxmlhttp, Microsoft.xmlhttp
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值