Herzlich willkommen in der Delphi-PRAXiS, white-desert.
Ich habe zum Testen D7, Indy9 und Sambar63 verwendet - und es funktioniert!
Delphi-Quellcode:
function Download(
const url:
String; fnLocal: TFileName): Boolean;
var
fs: TStream;
s: TStrings;
ftp: TIdFTP;
begin
s := TStringList.Create;
if CrackUrl(
url, s)
and (AnsiIndexText(s.Values['
scheme'], ['
ftp', '
']) >= 0)
then
begin
ftp := TIdFTP.Create(Application);
ftp.Host := s.Values['
hostname'];
if ftp.Host = '
'
then ftp.Host := '
localhost';
ftp.Username := s.Values['
username'];
if ftp.Username = '
'
then ftp.Username := '
anonymous';
ftp.Password := s.Values['
password'];
try
ftp.Connect;
if FileExists(fnLocal)
then fs := TFileStream.Create(fnLocal, fmOpenReadWrite
or fmShareDenyWrite)
else fs := TFileStream.Create(fnLocal, fmCreate);
if ftp.ResumeSupported
then
fs.Position := fs.Size;
try
ftp.Get(s.Values['
urlpath'], fs, fs.Position > 0);
Result := True;
finally
fs.Free;
end;
ftp.Disconnect;
except
Result := False;
end;
end else Result := False;
s.Free;
end;
// Getestet habe ich so:
procedure TDemoForm.DownloadButtonClick(Sender: TObject);
const
fn = '
c:\temp\demo.uxp';
url = '
ftp://localhost/demo.uxp';
begin
if FileExists(fn)
then
with TFileStream.Create(fn, fmOpenReadWrite
or fmShareDenyWrite)
do
begin
Size := Size
shr 1;
ShowMessage(Format('
size before download: %d', [Size]));
Free;
end;
if Download(
url, fn)
then
with TFileStream.Create(fn, fmOpenRead
or fmShareDenyNone)
do
begin
ShowMessage(Format('
size after download: %d', [Size]));
Free;
end;
end;
Vielleicht findest du deinen Fehler durch einen Vergleich mit meinem Code?
CrackUrl()
Freundliche Grüße vom marabu