ASP reads remote files and saves them to local code

Source: Internet
Author: User

<%
Dim act, iflogin, loginurl, loginacturl, logindata, fileurl, filename
Act = request. querystring ("act ")
If (Act = "do") then
Iflogin = CINT (request. querystring ("iflogin "))
Loginacturl = request. Form ("loginacturl ")
Logindata = request. Form ("logindata ")
Fileurl = request. Form ("fileurl ")
Filename = mid (fileurl, limit Rev (fileurl, "/") + 1)
Extpos = Limit Rev (filename ,"? ")
If (extpos> 0) then
Filename = left (filename, extPos-1)
End if
If (iflogin = 1) then
Call posthttppage (loginacturl, logindata)
End if
Call downloadfile (fileurl, filename)
Else
%>
<Form name = "form1" method = "Post" Action = "? Act = Do ">
<P> logon or not:
<Input name = "iflogin" type = "radio" value = "1">
Yes
<Input name = "iflogin" type = "radio" value = "0" Checked>
No </P>
<P> logon submission address:
<Input name = "loginacturl" type = "text" size = "50">
</P>
<P>
Logon data: <input name = "logindata" type = "text" size = "50">
</P>
<P>
The URL of the remote file to save:
<Input name = "fileurl" type = "text" size = "50">
</P>
<P>
<Input type = "Submit" name = "Submit" value = "Submit">
<Input type = "reset" name = "submit2" value = "Rewrite">
</P>
</Form>
<%
End if
Function bytestobstr (body, code)
Dim objstream
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1
Objstream. mode = 3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. type = 2
Objstream. charset = Code
Bytestobstr = objstream. readtext
Objstream. Close
Set objstream = nothing
End Function
Function posthttppage (loginacturl, postdata)
Dim XMLHTTP
Dim retstr
Set XMLHTTP = Createobject ("Microsoft. XMLHTTP ")
XMLHTTP. Open "Post", loginacturl, false
XMLHTTP. setRequestHeader "Content-Length", Len (postdata)
XMLHTTP. setRequestHeader "Content-Type", "application/X-WWW-form-urlencoded"
XMLHTTP. Send postdata
If err. Number <> 0 then
Set XMLHTTP = nothing
Response. Write ("An error occurred while submitting logon! Submit data: "& postdata)
Exit Function
End if
Posthttppage = bytestobstr (XMLHTTP. responsebody, "gb2312 ")
Set XMLHTTP = nothing
End Function
'''''''''''''''''''''''''''''''''''''''' '''
Function downloadfile (URL, filename)
Set xml = server. Createobject ("msxml2.xmlhttp") 'create an object

XML. Open "get", URL, false
XML. Send' send request

If err. number> 0 then
response. status = "404"
else
response. contenttype = "application/octet-stream"
response. addheader "content-Disposition:", "attachment; filename =" & filename
range = mid (request. servervariables ("http_range"), 7)
If range = "" Then
response. binarywrite (XML. responsebody)
else
S. position = clng (split (range, "-") (0)
response. binarywrite (XML. responsebody)
end if
response. end
set xml = nothing
end function
'''''''''''''''''''''''' '''
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.