FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Automatically Download File from website
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Automatically Download File from website
Posted: Thu Jul 26, 2012 01: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Automatically Download File from website
Posted: Thu Jul 26, 2012 01:53 PM
Try this:

Code (fw): Select all Collapse
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
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Automatically Download File from website
Posted: 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
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Automatically Download File from website
Posted: 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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Automatically Download File from website
Posted: Fri Jul 27, 2012 05:03 PM
This is the way I download a file :
Code (fw): Select all Collapse
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 (fw): Select all Collapse
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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Automatically Download File from website
Posted: Tue Jul 31, 2012 03:12 AM

Thank you Michel!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com

Continue the discussion