下载一个目录: function tftp.ex_download(remote_dir,local_dir:string):boolean; var i,j,count1:integer; att,ss:string; current_dir:string; temp_dir:string; begin try begin NMFTP1.ChangeDir(remote_dir); current_dir:=remote_dir; temp_dir:=copy(current_dir,2,length(current_dir)); if not DirectoryExists(local_dir) then CreateDir(local_dir); if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir); nmftp1.ParseList:=true; NMftp1.list; count1:=nmftp1.FTPDirectoryList.name.Count; for i:=0 to count1-1 do begin file://必须 NMFTP1.ChangeDir(current_dir); nmftp1.list; ss:=nmftp1.FTPDirectoryList.name.Strings[i]; att:=nmftp1.FTPDirectoryList.Attribute.Strings[i]; if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then begin if not DirectoryExists(local_dir) then CreateDir(local_dir); NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss); end else begin if not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss); file://递归调用 ex_download(remote_dir+ss+'\',local_dir); end; end; result:=true; end except On E:Exception do begin result:=false; end; end; end;
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(下载文件)等
function tftp.ex_download(remote_dir,local_dir:string):boolean;
var
i,j,count1:integer;
att,ss:string;
current_dir:string;
temp_dir:string;
begin
try begin
NMFTP1.ChangeDir(remote_dir);
current_dir:=remote_dir;
temp_dir:=copy(current_dir,2,length(current_dir));
if not DirectoryExists(local_dir) then CreateDir(local_dir);
if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);
nmftp1.ParseList:=true;
NMftp1.list;
count1:=nmftp1.FTPDirectoryList.name.Count;
for i:=0 to count1-1 do begin
file://必须
NMFTP1.ChangeDir(current_dir);
nmftp1.list;
ss:=nmftp1.FTPDirectoryList.name.Strings[i];
att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];
if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then begin
if not DirectoryExists(local_dir) then CreateDir(local_dir);
NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);
end
else begin
if not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);
file://递归调用
ex_download(remote_dir+ss+'\',local_dir);
end;
end;
result:=true;
end
except
On E:Exception do begin
result:=false;
end;
end;
end;
NMHTTP1.InputFileMode := ture;
NMHTTP1.Body := '本地文件名';
NMHTTP1.Header := 'Head.txt'; NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
NMHTTP1.Proxy := '代理服务器的IP地址';
NMHTTP1.ProxyPort := '代理服务器的端口号';
With NMHTTP1.HeaderInfo do
Begin
Cookie := '';
LocalMailAddress := '';
LocalProgram := '';
Referer := '';
UserID := '用户名称';
Password := '用户口令';
End; NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);