<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Option Explicit%>
<%
Rem ## 远程获得内容
Rem #################################################################
Function GetBinaryContent(strUrl)
GetBinaryContent = Null
Dim oXhttp, strContent
Set oXhttp = Server.CreateObject("Microsoft.XMLHTTP")
'On Error Resume Next
With oXhttp
.Open "GET", strUrl, False, "", ""
.Send
Rem ## 如果请求的文件存在
If .Status = 200 Then
GetBinaryContent = .Responsebody
'GetBinaryContent = .responseStream
Else
GetBinaryContent = Null
response.Write(vbCrLf & "//404")
response.Write(vbCrLf & strUrl)
End If
'response.Write("strUrl: " & strUrl & "<br>")
'strContent = .Responsebody
'response.Write("readystate: " & .readystate & "<br>")
'response.Write("Status: " & .Status & "<br>")
'response.Write("StatusText : " & .StatusText & "<br>")
'strContent = sBytesToBstr(strContent)
'response.Write(GetBinaryContent)
End With
Set oXhttp = Nothing
'If Err.Number <> 0 Then
'response.Write("Error!")
'Err.Clear
'End If
End Function
Rem #################################################################
Rem #################################################################
Rem ## 编码转换 2进制 => 字符串
Function sBytesToBstr(vIn)
If IsNull(vIn) Then
sBytesToBstr = ""
Exit Function
End If
dim objStream
set objStream = Server.CreateObject("adodb.stream")
objStream.Type = 1
objStream.Mode = 3
objStream.Open
objStream.Write vIn
objStream.Position = 0
objStream.Type = 2
objStream.Charset = "GB2312"
sBytesToBstr = objStream.ReadText
objStream.Close
set objStream = nothing
End Function
Rem #################################################################
Function GetTextContent(strUrl)
GetTextContent = sBytesToBstr(GetBinaryContent(strUrl))
End Function
Rem ## 建立目录的程序,如果有多级目录,则一级一级的创建
Rem #################################################################
Function CreateDir(strLocalPath)
CreateDir = False
Dim strLocalFolder
Dim strPath, tmpPath, tmptPath
Dim arrPathList, intLevel
strLocalFolder = Server.MapPath("/")
If Left(strLocalPath, Len(strLocalFolder)) <> strLocalFolder Then
Exit Function
End If
Rem ## 获得目录
strPath = Replace(strLocalPath, strLocalFolder, "")
If Left(strPath, 1) = "\" Then
strPath = Right(strPath, Len(strPath) - 1)
End If
Dim objFolder
Set objFolder = server.CreateObject("Scripting.FileSystemObject")
arrPathList = Split(strPath, "\")
intLevel = UBound(arrPathList)
Dim i
tmptPath = ""
For i = 0 To intLevel
tmptPath = tmptPath & arrPathList(i) & "\"
tmpPath = strLocalFolder & "\" & tmptPath
If Not objFolder.FolderExists(tmpPath) Then objFolder.CreateFolder tmpPath
Next
Set objFolder = Nothing
CreateDir = True
End Function
Rem #################################################################
Rem #################################################################
Rem ## Fso 生成文件
Function fDoDeleteFile(strFileName)
fDoDeleteFile = False
'response.Write(strFileName)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strFileName)) Then
fso.DeleteFile(strFileName)
fDoDeleteFile = True
Else
fDoDeleteFile = False
End If
Set fso = nothing
End Function
Rem #################################################################
Rem #################################################################
Rem ## Stream 生成文件
Function sDoCreateFile(strFileName, ByRef strContent)
sDoCreateFile = False
Dim strPath
strPath = Left(strFileName, InstrRev(strFileName, "\", -1, 1))
Rem ## 检测路径及文件名有效性
If Not(CreateDir(strPath)) Then Exit Function
'If Not(CheckFileName(strFileName)) Then Exit Function
'response.Write(strFileName)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strFileName, ForWriting, True)
f.Write strContent
f.Close
Set fso = nothing
Set f = nothing
sDoCreateFile = True
End Function
Rem #################################################################
%>
Dim dtaQueryUpdate, intHourDiff, strForceUpdate
strForceUpdate = LCase(request.QueryString("f"))
dtaQueryUpdate = request.QueryString("q")
If IsDate(dtaQueryUpdate) Then
dtaQueryUpdate = CDate(dtaQueryUpdate)
Else
dtaQueryUpdate = Now()
End If
intHourDiff = DateDiff("h", dtaQueryUpdate, Now())
If (intHourDiff > GI_DIFFNUMBER) Or (strForceUpdate = "yes") Then
On Error Resume Next
Call doCreateFile()
If Err Then
Err.Clear
response.Write(vbCrLf & "//程序执行错误")
Else
response.Write(vbCrLf & "//程序执行完毕")
End If
Else
response.Write(vbCrLf & "//已更新")
End If
Sub doCreateFile()
Dim strSourceFile, strTargetFile, strTargetFolder
Dim strFileContent
strFileContent = GetTextContent(strGetUrl) & ""
If Not CreateDir(Server.MapPath(strTargetFolder)) Then
response.Write(vbCrLf & "//创建目录" & strTargetFolder & "出错")
End If
If strFileContent <> "" Then
Dim strLocalUrl, strJsCode
strLocalUrl = request.ServerVariables("SCRIPT_NAME")
strJsCode = vbCrLf & "<img width=""0"" height=""0"" src=""" & strLocalUrl & "?q=" & Server.URLEncode(Now()) & """>" & "<!--" & Now() & "-->"
Call sDoCreateFile(Server.MapPath(strTargetFolder & strTargetFile), strFileContent & strJsCode)
Else
response.Write(vbCrLf & "//空")
End If
End Sub
%>