URLDownloadToFile()

URLDownloadToFile()

Postby Baxajaun » Tue Aug 09, 2016 6:56 am

Good morning,

i'm using Antonio's sample http://forums.fivetechsupport.com/viewtopic.php?f=3&t=32310 to download a file from URL, the file hasn't downloaded completed. But if i put the URL in the navigator, the file download completed.
Have you the same problema ? Have you solved ?

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

Re: URLDownloadToFile()

Postby Enrico Maria Giordano » Tue Aug 09, 2016 7:58 am

This is what I'm using to download a file from http url. Try it and let me know if it works for you.

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cUrl := "http://www.emagsoftware.it/charlie.gif"

    ? DELETEURLCACHEENTRY( cUrl )

    ? GETLASTERROR()

    ? GETURLTOFILE( cUrl )

    RETURN NIL


DLL STATIC FUNCTION DELETEURLCACHEENTRY( cUrl AS LPSTR ) AS BOOL;
    PASCAL FROM "DeleteUrlCacheEntryA" LIB "wininet.dll"


STATIC FUNCTION GETURLTOFILE( cUrl, cFile, lAuth )

    LOCAL lOk := .F.

    LOCAL oCli

    DEFAULT lAuth := .F.

    TRY
        oCli = TIPClientHttp():New( cUrl )

        IF lAuth; oCli:UseBasicAuth(); ENDIF

        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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: URLDownloadToFile()

Postby Baxajaun » Tue Aug 09, 2016 9:28 am

Thanks Enrico !

The problem is from googledrive, the directory is not shared as public. We must shared as public if we want to downloaad it.

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

Re: URLDownloadToFile()

Postby Enrico Maria Giordano » Tue Aug 09, 2016 9:47 am

Can't you use userid and password embedded in the url?

Sample:

http://userid:password@www.emagsoftware.it

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

Re: URLDownloadToFile()

Postby Baxajaun » Tue Aug 09, 2016 11:27 am

Enrico,

is a file from shared folder on Google Drive. Is enough sharing as "Public folder".

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



Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests