Download internet file without interference

yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Download internet file without interference

Post 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
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Re: Download internet file without interference

Post 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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post 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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Patrick,

Thanks for your answer.

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

What now ?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post 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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Patrick,

Sorry, I looked over it.

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Post by yury »

Patrick, perfect !

thanks very much

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post 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
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post 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
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Mr.Patrick

Thank you very much.

- Ramesh Babu P
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Post by MOISES »

Patrick,
Is it available for Harbour?
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post by Patrick Mast »

MOISES wrote:Is it available for Harbour?
Yes, I think Harbour did port the TIP library yes.

Patrick
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post 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
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Post 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,
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
Post Reply