This article illustrates how Delphi resolves an ftp address. Share to everyone for your reference. The implementation method is as follows:
Procedure Tform1.ftpanalysis (S:string;var username,password,ip,filename:string;var dirlist:tstringlist);
var I,j:integer;
strauthorization,straddr,strdirfile:string;
Authorization information begin username:= ' anonymous ';
password:= ' test@test.com ';
IP: = ';
STRADDR: = Copy (S,7,length (S)-6); The partial//s format after obtaining ftp://must be similar to Ftp://rec:ooo@192.168.76.11/20050418/abcdef.vox,//or ftp://192.168.76.11/... I: = Pos ('
@ ', S);
if (i>0) THEN begin strauthorization: = Copy (s,7,i-7);
Only take account password field j:=pos (': ', strauthorization);
if (j<1) then exit;
UserName: = Copy (strauthorization,1,j-1);
PassWord: = Copy (Strauthorization,j+1,length (strauthorization)-j);
End
I: = Pos (' @ ', straddr);
J:=pos ('/', straddr);
if (j>0) then IP: = Copy (straddr,i+1,j-i-1);//Get IP address strdirfile: = Copy (Straddr,j+1,length (STRADDR)-j);
Dirlist.delimiter: = '/'; Dirlist.delimitedtext: = strdirfile;//Get directory list filename: = dirlist[dirlist.count-1];//The last part is the filename dirlist.delete (
DIRLIST.COUNT-1); End
I hope this article will help you with your Delphi program.