procedure SendFile(lpFileName:
string; Socket1: TClientSocket);
var
F:
file;
FileInfo: TFileInfo;
dwFileSize, dwBytesRead: DWORD;
Buffer:
array[0..4096]
of Char;
begin
{$I-}
AssignFile(F, lpFileName);
Reset(F, 1);
dwFileSize := FileSize(F);
FileInfo.FileName := lpFileName;
FileInfo.FileSize := dwFileSize;
Socket1.SendBuffer(FileInfo, SizeOf(FileInfo));
repeat
FillChar(Buffer, SizeOf(Buffer), 0);
BlockRead(F, Buffer, SizeOf(Buffer), dwBytesRead);
Socket1.SendBuffer(Buffer, dwBytesRead);
until (dwBytesRead = 0);
CloseFile(F);
{$I+}
end;
procedure ReceiveFile(Socket1: TClientSocket);
var
F:
file;
lpFileName:
string;
FileInfo: TFileInfo;
dwFileSize, dwBytesRead: DWORD;
Buffer:
array[0..4096]
of Char;
begin
Socket1.ReceiveBuffer(FileInfo, SizeOf(TFileInfo));
lpFileName := FileInfo.FileName;
dwFileSize := FileInfo.FileSize;
{$I-}
AssignFile(F, lpFileName);
ReWrite(F, 1);
repeat
FillChar(Buffer, SizeOf(Buffer), 0);
dwBytesRead := Socket1.ReceiveBuffer(Buffer, SizeOf(Buffer));
BlockWrite(F, Buffer, dwBytesRead);
Dec(dwFileSize, dwBytesRead);
until (dwFileSize <= 0);
CloseFile(F);
{$I+}
end;