Programatically downloading a file from the internet

D

DKS

Hi,

I have a url address that points to a file on the internet. I would like to
programatically save this file on my local disk. How can I do that using
Access?

My requirement is:
Input: valid url address
Output: file saved to local disk

Many thanks in anticipation.
 
D

DKS

I tried the code but nothing happens. Hereunder is a copy paste of the code
- I executed the DOWNLOADFILE sub, but nothing happens.

??



Option Compare Database

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

Function DownloadURL(sSourceUrl As String, sLocalFile As String) As Boolean
DownloadURL = (URLDownloadToFile(0&, sSourceUrl, sLocalFile, 0&, 0&) = 0)
End Function

Sub DownloadFile()
Dim success As Boolean
success = DownloadURL("http://www.microsoft.com", "c:\TestFile.txt")
End Sub
 
J

Jack Leach

This code actually takes the source code from behind the page you are viewing
and downloads that to a text file. I've never tried it for downloading any
particular "files" such as a xls or pdf or doc or any of the sort.

If this is your goal, you may need to use an ftp to accomplish the task.
I've never worked with it myself, but I believe there's a few solutions for
this floating around to aid in this.

http://www.devhut.net/index.php?lang=en&id=0000000028

There's one link on the subject... there's a few more but I don't have them
handy at the moment. If I remeber correctly MVP Albert Kallal has some
information on it as well.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

DKS

Even for a simple page (html) there is no file downloaded. I also tried the
algorithm of Dev Ashish that you pointed to in your reply. But could not get
it to work.

Never mind. Thanks for all your help and suggestions.
 
J

Jack Leach

Even for a simple page (html) there is no file downloaded.

This is odd, I've used the API numberous times to download information from
weather sites and analyze them for data. If you tried the example per
Stuart, which retreives the source of www.microsoft.com, and saves it to a
text on your C: drive, you may not have write permissions for the C:\ root.
You can try experimenting with different locations, and verifying that the
URL you are trying is valid.

I have this API set up to run every two hours to collect wx info, and has
been doing so for about 3 months now without fail. Permissions on the source
file locatation or an invalid URL should be the only things that would cause
problems (unless you changed something in the API call).

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top