-
Notifications
You must be signed in to change notification settings - Fork 24
/
getRemoteFile.p
35 lines (26 loc) · 1.12 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
/*------------------------------------------------------------------------
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.
{&_proparse_prolint-nowarn(varusage)}
DEFINE VARIABLE iResult AS INT64 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).
{&_proparse_prolint-nowarn(varusage)}
IF SESSION:CPINTERNAL = 'UTF8'
THEN RUN urlDownloadToFileW (0, pcRemoteFile, cTempFile, 0, 0, OUTPUT iResult).
ELSE RUN urlDownloadToFileA (0, pcRemoteFile, cTempFile, 0, 0, OUTPUT iResult).
/* Read */
IF SEARCH(cTempFile) <> ? THEN COPY-LOB FILE cTempFile TO pcContents.
pcContents = TRIM(pcContents).
/* Cleanup */
OS-DELETE VALUE(cTempFile).