-
Notifications
You must be signed in to change notification settings - Fork 24
/
getRemoteFile.p
48 lines (37 loc) · 1.45 KB
/
getRemoteFile.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*------------------------------------------------------------------------
Name: getRemoteFile.p
Desc: Return a remotely hosted file as longchar
------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER pcRemoteFile AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcContents AS LONGCHAR NO-UNDO.
PROCEDURE URLDownloadToFileA EXTERNAL "URLMON.DLL" :
DEFINE INPUT PARAMETER pCaller AS LONG.
DEFINE INPUT PARAMETER szURL AS CHARACTER.
DEFINE INPUT PARAMETER szFilename AS CHARACTER.
DEFINE INPUT PARAMETER dwReserved AS LONG.
DEFINE INPUT PARAMETER lpfnCB AS LONG.
DEFINE RETURN PARAMETER ReturnValue AS LONG.
END PROCEDURE. /* URLDownloadToFileA */
PROCEDURE DeleteUrlCacheEntry EXTERNAL "WININET.DLL" :
DEFINE INPUT PARAMETER lbszUrlName AS CHARACTER.
END PROCEDURE. /* DeleteUrlCacheEntry */
/* Main
*/
DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
DEFINE VARIABLE cTempFile AS CHARACTER NO-UNDO.
/* Figure out a temp name */
#GetName:
REPEAT:
cTempFile = SUBSTITUTE('&1_remote-file-&2.txt', SESSION:TEMP-DIRECTORY, ETIME).
IF SEARCH(cTempFile) = ? THEN LEAVE #GetName.
END.
/* Download */
RUN DeleteURLCacheEntry (INPUT pcRemoteFile).
RUN urlDownloadToFileA (0, pcRemoteFile, cTempFile, 0, 0, OUTPUT iResult).
/* Read */
IF SEARCH(cTempFile) <> ? THEN COPY-LOB FILE cTempFile TO pcContents.
pcContents = TRIM(pcContents).
/* Cleanup */
FINALLY:
OS-DELETE VALUE(cTempFile).
END FINALLY.