Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   FTP URL in Bestandteile splitten (https://www.delphipraxis.net/50411-ftp-url-bestandteile-splitten.html)

eyeless 20. Aug 2005 15:26

Re: FTP URL in Bestandteile splitten
 
hallo,

wie ist denn das jetzt, wenn man als passwort eine email hat: ftp://anonymous:eine@mail.de@server.com:21/www/file.ext
bei den beispielen hier, TIdURI und internetcrackurl wird als passwort 'eine' und als host 'mail.de@server.com' zurückgegeben ... was nun?

sECuRE 20. Aug 2005 15:57

Re: FTP URL in Bestandteile splitten
 
Hi,

ich würde es mit dem für URL encodierten Code für das @-Zeichen probieren: %40, also sollte die URL dann so aussehen: "ftp://benutzer:e%40mail.de@server:port/verzeichnis/file.ext".

Auf http://www.w3schools.com/tags/ref_urlencode.asp kann man diese Codes nachlesen.

cu

Flocke 20. Aug 2005 15:59

Re: FTP URL in Bestandteile splitten
 
Da musst du den ersten Klammeraffen wohl Url-encoden '@' => %40, also
ftp://anonymous:eine%40mail.de@serve...1/www/file.ext

//EDIT: roten Kasten ignoriert

eyeless 23. Aug 2005 22:01

Re: FTP URL in Bestandteile splitten
 
mein vorschlag: (funzt mit emails im user und pass)

Delphi-Quellcode:
type
  TMyURL = record
   url, protocol, user, pass, host, port, path, filename : String;
  end;

function CrackUrl(url : String; var res : TMyURL):boolean;
var
  atpos, tmppos : integer;
  hp, rest : string;
begin
try
 tmppos := 0;
 res.url := url;
 res.protocol := copy(url,0,pos('://',url)-1);
 url := copy(url,pos('://',url)+3,length(url));
 res.user := copy(url,0,pos(':',url)-1);
 url := copy(url,pos(':',url)+1,length(url));
 repeat
  atpos := tmppos;
  tmppos := PosEx('@',url,tmppos+1);
 until tmppos+atpos = atpos;
 res.pass := copy(url,0,atpos-1);
 url := copy(url,atpos+1,length(url));
 hp := copy(url,0,pos('/',url)-1);
 if pos(':',hp)=0 then
  begin
   res.host := hp;
   res.port := '21';
  end
 else
  begin
   res.host := copy(hp,0,pos(':',hp)-1);
   res.port := copy(hp,pos(':',hp)+1,length(hp));
  end;
 url := copy(url,pos('/',url),length(url));
 res.filename := fMain.GetFileName(url);
 if (res.filename = '') or (pos('.',res.filename)=0) then
  res.path := copy(url,0,length(url))
 else
  res.path := copy(url,0,pos(res.filename,url)-1);
 Result := true;
except
 Result := false;
end;
end;
GetFilename kopiert einfach nur den filename raus ...

das ganze könte man jez noch mehr absichern, indem man auch des letzte ':' und auch auf unglückliche '/' im user/pass prüft ...

mfg, eyeless


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:00 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz