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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download File from The Web

Status
Not open for further replies.

siebel2002

Programmer
Oct 8, 2001
102
0
0
US
Currently I carry out the following series of tasks manually. Is there a way to automate the process? Tahnk you.

1. Paste an an Internet address in the browser window and click GO

2. The host web site come up on the screen, with a log-In screen for user Name & Password. I enter the same and click OK. A new screen comes up which has the link to a site I need to open up. I click on that link

3. I now see a screen with yet another link for the File of interest, which I click. This begins the process of downloading a zip file to my directory.

4. I now double click on the zip file and get my file.

Thanks again gurus!!!
 
Hi,

For task 1, use

Application.FollowHyperlink " to open the default web browser at your website.

Task 2 is a little more complicated. If the username/password can be passed across as part of the URL
(eg then you can do this, but...

task 3 will give a hyperlink - why not just connect direct to that particular file? If the name will change, this is a problem, but does this page showing the filename have the same URL each time? If so, go straight to here, then click the link.

John
 
You can often include the username and password in the url like:



An easy way to get the file is using an API call:

Private Declare Function DoFileDownload Lib "shdocvw" _
(ByVal lpszFile As String) As Long


Sub Download(strFTPPath)

Dim sDownload As String

sDownload = StrConv(strFTPPath, vbUnicode)
Call DoFileDownload(sDownload)

End Sub

Calling the sub download with the url of the file will open the save as dialog and download the requested file. Can't work out how to specify the download folder yet, but will keep looking. To unzip the file you could run the command line of winzip or use the vbzip.dll api from your code. I'm working on some code for that at the minute & will post it on my website later.

Cheers

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Typical, 2 minutes after you say you can't find it, you find it:

Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Const ERROR_SUCCESS As Long = 0

Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean

'if the API returns ERROR_SUCCESS (0),
'return True from the function
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS

End Function

call it like:
DownloadFile "
and your file will be saved onto the c:\ drive.

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top