티스토리 뷰
Delphi Tip - File Download
출처 : http://delphi.about.com/od/internetintranet/a/get_file_net.htm
uses WinInet;
function GetInetFile (const fileURL, FileName: String): boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
result := false;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
try
AssignFile(f, FileName);
Rewrite(f,1) ;
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
until BufferLen = 0;
CloseFile(f) ;
result := True;
finally
InternetCloseHandle(hURL);
end
finally
InternetCloseHandle(hSession);
end;
end;
// 윈도우즈의 임시폴더 명을 반환한다.
function SysTempPath(): String;
var
Buffer: array[0..1023] of Char;
begin
SetString(Result, Buffer, GetTempPath(Sizeof(Buffer)-1, Buffer));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
internetFile,
localFileName: string;
begin
internetFile := 'http://localhost:8080/Sample.jmd';
localFileName := SysTempPath() + 'test.xml';
if GetInetFile(internetFile, localFileName) then
ShowMessage(SysTempPath() + 'Sample.jmd' + ' / Download successful.')
else
ShowMessage('Error in file download.') ;
end;
- Total
- Today
- Yesterday
- JavaScript
- 레이싱모델 익스트림 포토 페스티벌
- flex
- Delphi
- 송주경
- ubuntu
- 일본여행
- koba2010
- Spring MVC
- Java
- 전예희
- Spring
- KOBA
- sas2009
- Mac
- 지스타2007
- android
- SAS
- Linux
- Delphi Tip
- NDK
- 서울오토살롱
- 동경
- ffmpeg
- ble
- 튜닝쇼 2008
- MySQL
- BPI-M4
- oracle
- Xcode
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |