Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method to download file from web site

Status
Not open for further replies.

magnaral

Programmer
Sep 29, 2004
11
NO
Hello

Does anyone know if there exists a method to download files from the web and save them on the local disk? I have looked at the CopyFile method, but it seems like it is not able to recognize web links, only normal local paths.


Alexander
 
Hi,

Check out

How to use a script of FTP commands from *.bat files
faq616-3355.

Are you actually transferring a file or is it a web page?

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
It is a .csv file, choose for yourself.

Alexander
 
You could also bring it down as binary with WinHTTP. I am not an Excel guy, so I have no idea what complex conditions may be affected by using this method, but I did do a simple test and it worked.

Code:
Sub GetmyCSV()
Dim WinHttpReq As WinHttp.WinHttpRequest
    ' Create an array to hold the response data.
    Dim d() As Byte
    
    Set WinHttpReq = New WinHttpRequest
    ' Assemble an HTTP Request.
    WinHttpReq.Open "GET", _
      "[URL unfurl="true"]http://test.bc.prv/corpserv/cis/sit/test.csv"[/URL]

    ' Send the HTTP Request.
    WinHttpReq.Send
  
    ' Put response data into a file.
    Open "c:\testmycsv.csv" For Binary As #1
    d() = WinHttpReq.ResponseBody
    Put #1, 1, d()
    Close
End Sub

Gerry
 
Maybe you know what libraries must be added to make the WinHttp.WinHttpRequest object being recognized?

Alexander
 
I found the library I needed. But there is yet another problem.

The page I want to download is not public, you have to log in with user name and password (a grey box with a picture of a key is popping up). How can I automize this routine as well?


Alexander
 
I do a little testing of your method, writing in different web addresses, but I always get the same response: "A connection with the server could not be established"

Alexander
 
Have you got a solution for the error message "A connection with the server could not be established" as well? I am sitting inside a financial department in a bank, so I guess there are some firewalls set up (but I thought calls to http-pages went through a standard port.

Unfortunately I am not able to open the file from the web directly into Excel, because it consists of over 400,000 lines (Excel is limited to 65536 rows), and I have to make a standard DB query with MS Text Driver.


Alexander
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top