本文實例講述了Delphi解析FTP位址的方法。分享給大家供大家參考。具體實作方法如下:
procedure TForm1.FTPAnalysis(S:string;var UserName,Password,IP,FileName:String;var DirList:TStringList);var i,j:integer; strAuthorization,strAddr,strDirFile:string; //授權資訊begin UserName:= ' anonymous'; Password:= '[email protected]'; IP := ''; strAddr := Copy(S,7,length(S)-6); //取得ftp://之後的部分//S 格式必須是類似ftp://rec:[email protected]/20050418/abcdef.vox,/ /或ftp://192.168.76.11/...... i := Pos('@',S); if(i>0) then begin strAuthorization := Copy(S,7,i-7); //只取帳號密碼欄位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);/ /取得IP位址strDirFile := Copy(strAddr,j+1,length(strAddr)-j); DirList.Delimiter := '/'; DirList.DelimitedText := strDirFile;//取得目錄清單FileName := DirList[DirList.count-1];//最後部分為檔案名稱DirList.Delete(DirList.Count-1);end;
希望本文所述對大家的Delphi程式設計有幫助。