How to avoid the receive (if not exists) or discard file (if exists)
My code is
Send code:
Delphi-Quellcode:
...
TCPAggiorna.SendCmd ('aggiorna');
for i:=0 to ElencoFile.Count - 1 do begin
FStream := TFileStream.Create(ElencoFile[i], fmOpenRead, fmShareDenyWrite);
TCPAggiorna.IOHandler.WriteLn(ExtractFileName(ElencoFile[i]));
TCPAggiorna.IOHandler.LargeStream := True;
TCPAggiorna.IOHandler.Write(FStream, 0, True);
FreeAndNil(FStream);
end;
TCPAggiorna.IOHandler.WriteLn('Finito');
....
Receive code
Delphi-Quellcode:
Dir := AppPath;
FileName:='';
i:=202;
repeat
inc(i);
FileName:= ASender.Context.Connection.IOHandler.ReadLn;
if (FileName <> 'Finito') then begin
if (FileExists(Dir+FileName)) then begin
// Insert here the code to discard file
ASender.Context.Connection.IOHandler.WriteLn (IntToStr(i)+' File '+FileName+' received');
end
else begin
FStream := TFileStream.Create(Dir+FileName, fmCreate, fmOpenWrite);
ASender.Context.Connection.IOHandler.LargeStream := True;
ASender.Context.Connection.IOHandler.ReadStream(FStream, -1);
FreeAndNil(FStream);
ASender.Context.Connection.IOHandler.WriteLn (IntToStr(i)+' File '+FileName+' discarded');
end;
end;
until FileName='Finito';