Page 1 of 3

Download internet file without interference

Posted: Mon Jul 14, 2008 4:35 pm
by yury
Hi everyone,

How can I download a file in "http:\\200.150.20.14\f_080714.xml"
and save the same in folder "f:\Sistem\xml\" without interference of user ?

I am using:

Code: Select all

cLink = "http:\\200.150.20.14\f_080714.xml"

ShellExecute(GetActiveWindow(),nil,cLink,"","",5)
It´s working, but the user need click in save button and choice the folder...

I would like do this automatically...

Many thanks

Regards

Re: Download internet file without interference

Posted: Mon Jul 14, 2008 6:38 pm
by Patrick Mast
yury wrote:How can I download a file in "http:\\200.150.20.14\f_080714.xml" and save the same in folder "f:\Sistem\xml" without interference of user ? I am using:

Code: Select all

cLink = "http:\\200.150.20.14\f_080714.xml"
ShellExecute(GetActiveWindow(),nil,cLink,"","",5)
It´s working, but the user need click in save button and choice the folder... I would like do this automatically...
I use this:

Code: Select all

FUNCTION wfReadURL(cUrl)
  LOCAL cPageContent:="Error: " + cUrl + " not found or timed out."
  LOCAL oConn
  
  IF Upper(Left(cUrl,4))#"HTTP"
     cUrl:="http://"+cUrl
  ENDIF
  
  TRY
  
   oConn := TipClientHttp():New(TURL():New(cUrl))
   oConn:nConnTimeout := 20000

   IF oConn:Open(cURL)
      cPageContent := oConn:ReadAll()
      oConn:Close()
   ENDIF
   
  CATCH
   cPageContent:="Error opening " + cUrl
   
  END
  
RETURN cPageContent


//================================================================================


FUNCTION wfSaveURL(cUrl,cSaveAs)

  LOCAL cPageContent:=wfReadURL(cUrl)
  LOCAL lReturn:=.T.
  
  IF cPageContent="Error:"
     lReturn:=.F.
  ELSE
     MemoWrite(cSaveAs,cPageContent)
     IF !File(cSaveAs)
        lReturn:=.T.
     ENDIF   
  ENDIF
  
RETURN lReturn
Patrick

Posted: Thu Jul 17, 2008 5:46 pm
by driessen
Patrick,

This is a topic which I am interested to.

Is there a possibility to check if a file exist on internet ?

For instance : can I check the existance of a file called :

http://www.test.be/test.txt ?

Thanks.

Posted: Thu Jul 17, 2008 5:49 pm
by Patrick Mast
driessen wrote:This is a topic which I am interested to. Is there a possibility to check if a file exist on internet ?

For instance : can I check the existance of a file called :
http://www.test.be/test.txt ?
Sure:

Code: Select all

IF wfReadURL("http://www.test.be/test.txt") # "Error opening"
   ... File is there
ELSE
   ... File is not there
ENDIF
Patrick

Posted: Thu Jul 17, 2008 10:00 pm
by driessen
Patrick,

Thanks for your answer.

I tried it out but I got an error "unresolved external symbol _HB_FUN_WFREADURL"

What now ?

Posted: Fri Jul 18, 2008 4:10 am
by Patrick Mast
driessen wrote:Thanks for your answer. I tried it out but I got an error "unresolved external symbol _HB_FUN_WFREADURL". What now ?
Comon ;-)
The wfReadURL() function is above in this thread :)

Patrick

Posted: Fri Jul 18, 2008 8:17 am
by driessen
Patrick,

Sorry, I looked over it.

Thanks.

Posted: Fri Jul 18, 2008 7:32 pm
by yury
Patrick, perfect !

thanks very much

regards

Posted: Sun Jul 20, 2008 2:52 am
by RAMESHBABU
Hello Mr.Patrick

Code: Select all

oConn := TipClientHttp():New(TURL():New(cUrl)) 
Please let me know TipClientHttp() and TURL() functions are available in which lib ?

- Ramesh Babu P

Posted: Sun Jul 20, 2008 9:59 pm
by Patrick Mast
Hello Ramesh,
RAMESHBABU wrote:

Code: Select all

oConn := TipClientHttp():New(TURL():New(cUrl)) 
Please let me know TipClientHttp() and TURL() functions are available in which lib ?
You need to include TIP.LIB

Patrick

Posted: Mon Jul 21, 2008 12:34 am
by RAMESHBABU
Mr.Patrick

Thank you very much.

- Ramesh Babu P

Posted: Mon Jul 21, 2008 8:19 am
by MOISES
Patrick,
Is it available for Harbour?

Posted: Mon Jul 21, 2008 4:16 pm
by Patrick Mast
MOISES wrote:Is it available for Harbour?
Yes, I think Harbour did port the TIP library yes.

Patrick

Posted: Wed Jul 23, 2008 1:15 am
by ShumingWang
hLib = LOADLIBRARY( "urlmon.dll")
if URLDownloadToFile( 0, "www.myweb.com/path/my.exe", "d:\downloadtopath\my.exe", 0, 0 ) == 0

Else
MsgStop("Not download", "Stop" )
exit
EndIf
FREELIBRARY( hLib )

DLL32 FUNCTION URLDownloadToFile(pCaller AS LONG,szURL AS STRING, szFileName AS STRING, dwReserved AS LONG, lpfnCB AS LONG);
AS LONG PASCAL;
FROM "URLDownloadToFileA";
LIB hlib

Regards!
Shuming Wang

Posted: Mon Nov 17, 2008 2:33 pm
by Horizon
Hi Patrick,

Code: Select all

IF oConn:Open(cURL) 
      cPageContent := oConn:ReadAll() 
      oConn:Close() 
   ENDIF 
Is it possible to show progress bar (for example in message bar) while reading at ReadAll() method?

I download big files from www. Users confuse if there is a problem or not.

Thanks,