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

Downloading a file from the web... 1

Status
Not open for further replies.

Neil Toulouse

Programmer
Mar 18, 2002
882
GB
thread184-1050873

I have been playing with the excellent advice contained in this thread to automate a download of a file, the data from which gets incorporated into our database. I am scraping a page to get the file name, building the download URL and using faq184-3838 to download the file.

All is working well, but is there anyway of programmatically specifying the folder to where the file will be downloaded, so the user is not prompted for this?

TIA

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Thanks Nigel!

Unfortunately I cannot get it to work. My code is:

Code:
SET LIBRARY TO (LOCFILE("vfpconnection.fll","fll"))

CLEAR
? HTTPGET("[URL unfurl="true"]http://gateway.imservices.org.uk/sites/LARA/Lists/LARAPubDBs/LARA_20110817_1112_PSV.zip",[/URL] "c:\#LARA\LARA_20110817_1112_PSV.zip", "", "")

SET LIBRARY TO

This always returns .F.

Can you see what I am doing wrong? The URL is fine if put into a browser, as in you are prompted to save the file.

Thanks

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Neil,

I've also had problems using Craig's VFPConnection FLL. I didn't spend any time trying to sort it out, and I can't tell you where you have gone wrong.

I switched to using Rick Strahl's Internet and Client Tools product ( So far, it seems to work fine (including the ability to specify the target directory).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Neil,

To answer your original question (how to avoid prompting the user for the target folder), I just found this:


It addresses that specific problem. (But I'm not sure whether it avoids the prompt completely, or simply changes the default to a directory of your choice; you might have to figure that out for yourself).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike

Thanks for the info! That's a shame. Not sure I will be allowed to spend money on this so may have to can it for now.

Oh well, I can get half way at least by 'scraping' for the filename and building the download URL.

I will have to see what the boss says... :)

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Two more solutions: Using URLDownloadToFile and MSXML2.XMLHttp


or

Code:
Local loRequest, lcUrl, lcFilename

lcUrl = "[URL unfurl="true"]http://gateway.imservices.org.uk/sites/LARA/Lists/LARAPubDBs/LARA_20110817_1112_PSV.zip"[/URL]
lcFilename = "C:\Temp\PSV.zip"

loRequest = Createobject('MsXml2.XmlHttp')
loRequest.Open("GET",lcUrl,.F.)
loRequest.Send()
StrToFile(loRequest.ResponseBody,lcFilename)

Bye, Olaf.
 
Yet another option to consider (a free one) is the Microsoft Internet Transfer control (this is one of the ActiveX controls that come with VFP):

Code:
lox = CREATEOBJECT("inetctls.inet")
lcSuff = lox.OpenURL("[URL unfurl="true"]http://whatever.co.uk/suff.htm")[/URL]
STRTOFILE(lcStuff, "c:\data\myfile.htm")

It's always worked for me. You might need to distribute the relevant OCX file with your app (MSINET.OCX) - not sure about that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Good point Mike,

I forgot about the Internet Transfer control.

URLDownloadToFile is a Windows API call granted to exist since way back. The MSDN lists it as present since Windows NT 4.0/ Windows 95.

The good thing about MsXML2.XMLHTTP also is, you can be sure it's already part of the system since at least Win98. It's the basis of AJAX techniques using XmlHttpRequest from MS/JScript within IE, see
Also, it downloads to memory like the Internet Transfer Control, so you can decide to store it on disc or use it right away, if it's not a zip, but html or text or you can store it into a blob field, eg.

Bye, Olaf.
 
that's the first time i've had trouble with vfpconnection.fll (and i too get the same problem using it to download your file).

i'll see if i can find out why

n
 
Using THAT link I once got the zip and the second time got a access denied answer/popup. so even though it's apublic download also from the name, it might not be the best and most repre4sentative example. They might have a limitation as one download of the same file per IP per day or whatever.

Bye, Olaf.
 
Thanks guys!

I will have a play tomorrow when I am back in the office and let you know the outcome.

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 

Mike
I tried your example, but get the error message:

Code:
OLE IDispatch exception code 0 from Inet: Type mismatch..


Olaf
Yay! Your example works a treat. I put it in a loop and downloaded the file 10 times in a row without a problem, so this is the method I will go for.

Thanks again guys, appreciate it :)



I like work. It fascinates me. I can sit and look at it for hours...
 
Neil,

I tried your example, but get the error message:

I could probably sort that out for you. But since you've got a good answer from Olaf, you might as well stay with that. (Unlike my suggestion, it doesn't depend on the presence of an external component.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mikes code is missing a t in the lcStuff Variable on the line [lcSuff = lox.OpenURL("] That's all.

It's just a bit funny, as Suff is the colloqial German word for booze. I don't think, though, that Mike was under the influence.

Bye, Olaf.
 
You never know :) I know I will certainly be under the influence later - just need to get out of the office!

...I put the 't' in lcSuff, but still get the same error message.

Not to worry I have your solution.

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top