bei
Indy 10 gibt es keine IOhandler.Readfile(...) Funktion.
Habe mir den Code selber zusammengebaut. Eine Datei vom Client zum Sever schicken geht, leider nicht vom Server zurück zum Client ...
Sieht jemand den Fehler im Code ??
Delphi-Quellcode:
///
/// --------------- HELPER FUNCTIONS FOR FILES EXCHANGE ----------------
///
function ClientSendFile(AClient: TIdTCPClient; Filename: String): Boolean;
begin
AClient.IOHandler.LargeStream := True; // fully support large streams
Result := True;
try
AClient.IOHandler.WriteFile(Filename); // send file stream data
except
Result := False;
end;
end;
function ClientReceiveFile(AClient: TIdTCPClient; Filename: String): Boolean;
var
// LSize: String;
AStream: TFileStream;
begin
try
Result := True;
AStream := TFileStream.Create(Filename, fmCreate + fmShareDenyNone);
try
AClient.IOHandler.ReadStream(AStream);
finally
FreeAndNil(AStream);
end;
except
Result := False;
end;
end;
function ServerSendFile(AContext: TIdContext; Filename: String): Boolean;
begin
AContext.Connection.IOHandler.LargeStream := True; // fully support large streams
Result := True;
try
AContext.Connection.IOHandler.WriteFile(Filename); // send file stream data
except
Result := False;
end;
end;
function ServerReceiveFile(AContext: TIdContext; ServerFilename: String;
var ClientFilename: String): Boolean;
var
// LSize: String;
AStream: TFileStream;
begin
try
Result := True;
AStream := TFileStream.Create(ServerFilename, fmCreate + fmShareDenyNone);
try
AContext.Connection.IOHandler.ReadStream(AStream);
finally
FreeAndNil(AStream);
end;
except
Result := False;
end;
end;