The example in this article describes how Delphi parses FTP addresses. Share it with everyone for your reference. The specific 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:= '[email protected]'; IP := ''; strAddr := Copy(S,7,length(S)-6); //Get the part after ftp:// //S format must be similar to ftp://rec:[email protected]/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 the 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,ji-1);//Get the 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 file name DirList.Delete(DirList.Count-1);end;
I hope this article will be helpful to everyone's Delphi programming.