Automatically Download File from website

Automatically Download File from website

Postby cdmmaui » Thu Jul 26, 2012 1:26 pm

Hello,

I need to create an FWH application that automatically downloads a file from a website so it can be processed. Does anyone have an example that they can share?

Thank you,
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Automatically Download File from website

Postby Enrico Maria Giordano » Thu Jul 26, 2012 1:53 pm

Try this:

Code: Select all  Expand view
FUNCTION GETURLTOFILE( cUrl, cFile )

    LOCAL lOk := .F.

    LOCAL oCli

    TRY
        oCli = TIPClientHttp():New( cUrl )

        IF EMPTY( oCli ); BREAK; ENDIF

        oCli:nConnTimeout = -1

        IF !oCli:Open(); BREAK; ENDIF

        DEFAULT cFile := oCli:oUrl:cFile

        IF !oCli:ReadToFile( cFile ); BREAK; ENDIF

        lOk = !EMPTY( oCli:cReply ) .AND. "OK" $ UPPER( oCli:cReply )

        IF !lOk; FERASE( cFile ); ENDIF
    CATCH
    END

    IF !EMPTY( oCli ); oCli:Close(); ENDIF

    RETURN lOk


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Automatically Download File from website

Postby hua » Thu Jul 26, 2012 10:08 pm

If you like some sort of auto-update routine http://bielsys.blogspot.com/ is a useful reference too (listed at http://wiki.fivetechsoft.com/doku.php?i ... _resources )
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Automatically Download File from website

Postby cdmmaui » Fri Jul 27, 2012 12:58 am

Thank you Enrico, that is what I was look for! I appreciate you help!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Automatically Download File from website

Postby driessen » Fri Jul 27, 2012 5:03 pm

This is the way I download a file :
Code: Select all  Expand view
TRY
   MsgRun("Downloading ...","One moment please ...",{||IF(URLDownloadToFile(0,"http://www.test.be/test.exe","C:\test.exe",0,0 ) == 0,UpdDown:=0,UpdDown:=1)})
CATCH
   // function in case the file is not found or no internet connection
END


At the end of my PRG-file, I add :
Code: Select all  Expand view
DLL Function URLDownloadToFile(pCaller AS LONG, szURL AS STRING, szFileName AS STRING, dwReserved AS LONG, lpfnCB AS LONG) AS LONG PASCAL FROM "URLDownloadToFileA" LIB "urlmon.dll"
 


It works just fine.

Good luck.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Automatically Download File from website

Postby cdmmaui » Tue Jul 31, 2012 3:12 am

Thank you Michel!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 96 guests