FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour URLDownloadToFile()
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
URLDownloadToFile()
Posted: Tue Aug 09, 2016 06: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: URLDownloadToFile()
Posted: Tue Aug 09, 2016 07: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 (fw): Select all Collapse
#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
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: URLDownloadToFile()
Posted: Tue Aug 09, 2016 09: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,

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: URLDownloadToFile()
Posted: Tue Aug 09, 2016 09:47 AM
Can't you use userid and password embedded in the url?

Sample:

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

EMG
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: URLDownloadToFile()
Posted: 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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM

Continue the discussion