download file from url

Post Reply
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

download file from url

Post by Natter »

Hi. all !

Is it possible to download a file from a URL (not via FTP)
User avatar
Enrico Maria Giordano
Posts: 8767
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: download file from url

Post by Enrico Maria Giordano »

Here it is:

Code: Select all | Expand

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
Baxajaun
Posts: 971
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: download file from url

Post by Baxajaun »

Hi Natter,

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

Best regards,
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: download file from url

Post by Natter »

Enrico, Baxajaun thanks !

Used the function UrlDownLoadToFile. Everything works fine
Post Reply