download file from url

download file from url

Postby Natter » Mon Apr 02, 2018 5:04 pm

Hi. all !

Is it possible to download a file from a URL (not via FTP)
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: download file from url

Postby Enrico Maria Giordano » Mon Apr 02, 2018 5:31 pm

Here it is:

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: download file from url

Postby Baxajaun » Mon Apr 02, 2018 5:42 pm

Hi Natter,

please, review [url]viewtopic.php?f=6&t=32803&p=193189&hilit=URLDownloadToFile#p193189[/url]

Best regards,
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: download file from url

Postby Natter » Tue Apr 03, 2018 6:30 am

Enrico, Baxajaun thanks !

Used the function UrlDownLoadToFile. Everything works fine
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests