Hello,
I need to create an FWH application that automatically downloads a file from a website so it can be processed. Does anyone have an example that they can share?
Thank you,
FUNCTION GETURLTOFILE( cUrl, cFile )
LOCAL lOk := .F.
LOCAL oCli
TRY
oCli = TIPClientHttp():New( cUrl )
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
TRY
MsgRun("Downloading ...","One moment please ...",{||IF(URLDownloadToFile(0,"http://www.test.be/test.exe","C:\test.exe",0,0 ) == 0,UpdDown:=0,UpdDown:=1)})
CATCH
// function in case the file is not found or no internet connection
END
DLL Function URLDownloadToFile(pCaller AS LONG, szURL AS STRING, szFileName AS STRING, dwReserved AS LONG, lpfnCB AS LONG) AS LONG PASCAL FROM "URLDownloadToFileA" LIB "urlmon.dll"
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 106 guests