Get remote files and save to local

Source: Internet
Author: User
Tags save file
<%
'****************************************************************************
' PageName:GetRemoteFiles.asp
' Function:download the files to Server
' Author:xiaotian
' Last Modified at:2003-3-19
'****************************************************************************
' Get the remote file and save it to the local
Function getremotefiels (RemotePath, LocalPath, FileName)
Dim strbody
Dim FilePath
On Error Resume Next
' Get the Flow
Strbody = GetBody (RemotePath)
' Get the 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
End If
End Function
' Get content remotely
Function getbody (URL)
Dim Retrieval
' Create a XMLHTTP object
Set retrieval = CreateObject ("Microsoft.XMLHTTP")
With retrieval
. Open "Get", url, False, "", ""
. Send
GetBody =. Responsebody
End With
Set retrieval = Nothing
End Function
' Reorganize filename
Function GetFileName (RemotePath, FileName)
Dim arrtmp
Dim Strfileext
Arrtmp = Split (RemotePath, ".")
Strfileext = Arrtmp (UBound (arrtmp))
GetFileName = FileName & "." & Strfileext
End Function
' Save stream content as a file
Function SaveToFile (Stream, FilePath)
Dim objstream
On Error Resume Next
' Create a ADODB.stream object that must be ADO 2.5 version
Set objstream = Server.CreateObject ("ADODB. Stream ")
objStream.Type = 1 ' Open in binary mode
objStream.Open
Objstream.write Stream
Objstream. SaveToFile FilePath, 2
Objstream. Close ()
' Close the object and release the resource
Set objstream = Nothing
If Err. Number <> 0 Then
SaveToFile = False
Else
SaveToFile = True
End If
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.