FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour download file from url
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
download file from url
Posted: Mon Apr 02, 2018 05:04 PM

Hi. all !

Is it possible to download a file from a URL (not via FTP)

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: download file from url
Posted: Mon Apr 02, 2018 05:31 PM
Here it is:

Code (fw): Select all Collapse
FUNCTION GETURLTOFILE( cUrl, cFile, cUsr, cPsw )

    LOCAL lOk := .F.

    LOCAL oHtp, oStr

    DEFAULT cFile := FILENAME( STRTRAN( cUrl, "/", "\" ) )

    TRY
        oHtp = CREATEOBJECT( "MSXML2.XMLHTTP" )

        oHtp:Open( "POST", cUrl, .F., cUsr, cPsw )

        oHtp:Send()

        IF oHtp:Status != 200 THEN BREAK

        oStr = CREATEOBJECT( "ADODB.Stream" )

        oStr:Open()

        oStr:Type = 1

        oStr:Write( oHtp:ResponseBody )

        oStr:SaveToFile( cFile, 2 )

        oStr:Close()

        lOk = .T.
    CATCH
    END

    RETURN lOk


EMG
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: download file from url
Posted: Mon Apr 02, 2018 05:42 PM
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: download file from url
Posted: Tue Apr 03, 2018 06:30 AM

Enrico, Baxajaun thanks !

Used the function UrlDownLoadToFile. Everything works fine

Continue the discussion