?
Solved

How ot use a script file  to download a file ?

Posted on 2003-03-25
9
Medium Priority
?
171 Views
Last Modified: 2010-05-01
I want to download a file from the web
like http://www.abc.com/file.txt , use the script file.
but there seems no object support this function.
0
Comment
Question by:Sam80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:Sam80
ID: 8203717
Thanks , aelatik .
The function is just what i want.
but in vb script ,I can not use the window api function,which force me had to find out an object that can attain this requirement.

I will be greatly appreciate to your new answer.
0
 
LVL 3

Accepted Solution

by:
emadat earned 200 total points
ID: 8203727
Copy this in a module and use it.
Usage:
sString = GetHTML("http:\\www.domain_name.com")

'====================================================
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_DEFAULT_HTTP_PORT = 80
Public Const INTERNET_SERVICE_HTTP = 3
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const HTTP_QUERY_STATUS_CODE = 19
Public Const HTTP_ADDREQ_FLAG_ADD = &H20000000

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" (ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
'Public Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, sOptional As Any, ByVal lOptionalLength As Long) As Long
Public Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As String, ByVal lOptionalLength As Long) As Long
Public Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Long
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lModifiers As Long) As Integer
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumberOfBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternet&, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength&, ByVal dwFlags&, ByVal dwContext&) As Long


Public Function GetHTML(strURL As String) As String
Const BufferSize = 16384
Dim hSession&, hURL&
Dim Buffer As String * BufferSize
Dim BufferLen&
Dim sAppName$, sResult$
   sAppName = "MyApplicationName"
   hSession = InternetOpen(sAppName, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
   hURL = InternetOpenUrl(hSession, strURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
   sResult = ""
   Do
       InternetReadFile hURL, Buffer, Len(Buffer), BufferLen
       If BufferLen > 0 Then sResult = sResult & Left(Buffer, BufferLen)
   Loop Until BufferLen = 0
   GetHTML = sResult
   InternetCloseHandle hURL
   InternetCloseHandle hSession
End Function
'====================================================
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:emadat
ID: 8203856
This function will work from VBS. It relies on MS XML

However, It might need some modification in creating the object. Try the commented line if the first did not work

Function GetHTML(sURL As String) As String
Dim objXMLHTTP, xml
    Set xml = CreateObject("Microsoft.XMLHTTP")
'    Set xml = CreateObject("MSXML2.XMLHTTP")
    xml.Open "GET", sURL, False
    xml.send
    GetHTML = xml.responseText
    Set xml = Nothing
End Function

Good luck
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8204754
If its just for text and other type of pages use :

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "http://www.abc.com/file.txt"
    While IE.Busy
    Wend
       GetHTMLCode = IE.Document.documentelement.innerHTML
MsgBox GetHTMLCode
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8205856
hearing...
0
 

Author Comment

by:Sam80
ID: 8232977
thanks , guys, excellent!!!

and now i want one more function is that save the file to the specific folder , how ?
0
 

Author Comment

by:Sam80
ID: 8233004
how about if my request file is not a text file ?
it might be any kind such as exe,jpg and so on.
0
 

Expert Comment

by:CleanupPing
ID: 8531635
Hi Sam80,
This old question (QID 20562465) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question