当前位置:首页 > 网络编程 > 软件语言 > DELPHI > 编程实现拨号网络连接及FTP应用

编程实现拨号网络连接及FTP应用

点击次数:45 次 发布日期:2008-11-09 08:41:57 作者:源代码网
源代码网推荐
广告载入中
本文介绍了Windows下如何在程序中加入拨号网络,如何自己编写
源代码网推荐 程序实现FTP功能。
源代码网推荐 Windows本身带有拨号网络功能。由于拨号网络不是一个可执行
源代码网推荐 文件,所以不能用 " WinExec 可执行文件"的方式来打开。要启动拨
源代码网推荐 号网络,需要用 Explorer ,方法如下:
源代码网推荐 WinExec(‘Explorer::
源代码网推荐 {20D04FE0 3AEA 1069 A2D8 08002B30309D}::
源代码网推荐 {992CFFA0-F557 101A 88EC 00DD010CCC48}",
源代码网推荐 SW_SHOWNA);
源代码网推荐 但若是要启动拨号网络中的某一个连接,则需借助rundll.exe 及
源代码网推荐 rnaui.dll来启动,方法如下(假定连接名称为MyFtpNet):
源代码网推荐 WinExec(‘rundll rnaui.dll,RnaDial MyFtpNet",SW_SHOWNA);
源代码网推荐 这样程序运行到此命令时,将会弹出拨号网络连接MyFtpNet窗口,
源代码网推荐 输入用户名、密码等信息即可登录,如想更加方便,则可对此连接编写
源代码网推荐 脚本文件,不需要用户输入任何信息, 使程序自动登录。
源代码网推荐 在Delphi中具有可用的FTP控件,所以使FTP编程将会变得极其方
源代码网推荐 便。下面我们对编写FTP应用的Form进行设计:
源代码网推荐 添加TNMFTP控件:NMFTP1
源代码网推荐 添加Label控件:Label1、Label2、Label3、Label4、Label5、La
源代码网推荐 bel6
源代码网推荐 Label1.Caption = ‘主机名称"
源代码网推荐 Label2.Caption = ‘主机端口号"
源代码网推荐 Label3.Caption = ‘用户名"
源代码网推荐 Label4.Caption = ‘用户口令"
源代码网推荐 Label5.Caption = ‘代理服务器"
源代码网推荐 Label6.Caption = ‘代理端口号"
源代码网推荐 添加Edit控件:HostTxt(FTP主机名)、PortTxt(FTP主机端口)、U
源代码网推荐 serTxt(用户名)、PassTxt(用户口令)、ProxyServerTxt(代理服务器
源代码网推荐 地址)、ProxyPortTxt(代理服务器端口)
源代码网推荐 添加CheckBox控件:CheckBox1CheckBox1.Caption = ‘使用代理
源代码网推荐 服务器"
源代码网推荐 添加Button控件:Button1(连FTP主机)、Button2(断开FTP主机)
源代码网推荐 、Button3(列FTP目录)
源代码网推荐 Button1.Caption = ‘连接"
源代码网推荐 Button2.Caption = ‘断开"
源代码网推荐 Button3.Caption = ‘列目录"
源代码网推荐 将以上控件以友好界面方式在Form中进行放置。
源代码网推荐 编写Button1的Click事件为:
源代码网推荐 procedure TForm1.Button1Click(Sender: TObject);
源代码网推荐 begin
源代码网推荐 If CheckBox1.Checked then
源代码网推荐 Begin
源代码网推荐 NMFTP1.Proxy := ProxyserverTxt.Text;
源代码网推荐 NMFTP1.ProxyPort := StrToInt(ProxyportTxt.Text);


源代码网推荐 End;
源代码网推荐 NMFTP1.Host := HostTxt.Text;
源代码网推荐 NMFTP1.Port := StrToInt(PortTxt.Text);
源代码网推荐 NMFTP1.Timeout := 5000;
源代码网推荐 NMFTP1.UserID := UserTxt.Text;
源代码网推荐 NMFTP1.Password := PassTxt.Text;
源代码网推荐 try
源代码网推荐 NMFTP1.Connect;
源代码网推荐 except
源代码网推荐 On E:Exception do
源代码网推荐 writeln(E.message);
源代码网推荐 end
源代码网推荐 end;
源代码网推荐 编写Button2的Click事件为:
源代码网推荐 procedure TForm1.Button2Click(Sender: TObject);
源代码网推荐 begin
源代码网推荐 NMFTP1.Disconnect;
源代码网推荐 end;
源代码网推荐 编写Button3的Click事件为:
源代码网推荐 procedure TForm1.Button3Click(Sender: TObject);
源代码网推荐 begin
源代码网推荐 try
源代码网推荐 NMFTP1.List;
源代码网推荐 except
源代码网推荐 end;
源代码网推荐 end;
源代码网推荐 另外FTP控件还具有其他功能,如:MakeDirectory(创建目录)、Re
源代码网推荐 moveDir(删除目录)、Rename(文件更名)、Delete(删除文件)、Uploa
源代码网推荐 d(上载文件)、Download(下载文件)等,在此不再讲述,大家如需要编
源代码网推荐 写这些功能,可自己增加。
源代码网推荐 本程序在Windows98 Delphi5.0下调试通过。


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华