查看: 88|回复: 0

[教程] Delphi解析FTP地址的方法

[复制链接]

1

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2009-3-17
发表于 2015-5-8 15:32:04 | 显示全部楼层 |阅读模式

本文实例讲述了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:= 'test@test.com';
 IP := '';
 strAddr := Copy(S,7,length(S)-6);
 //取得ftp://之后的部分
 //S 格式必须是类似ftp://rec:ooo@192.168.76.11/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,j-i-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程序设计有所帮助。

您可能感兴趣的文章:
  • Delphi7中群发Email邮件的方法
  • Delphi远程连接Mysql的实现方法
  • Delphi编程常用快捷键大全
  • Delphi实现获取磁盘空间大小的方法
  • Delphi实现限定软件使用时间的方法
  • Delphi实现图片滚动切换的完整实例代码
  • Delphi之Pascal语言中的关键字及保留字汇总
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部