to wjiachun:
我知道可能是这个原因,但我不知如何来改进,部分测试代码如下:
unit ftpmain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ftpdlg, Psock, NMFtp;
type
Tmain = class(TForm)
lst_local: TListBox;
lst_remote: TListBox;
btn_connect: TButton;
btn_close: TButton;
btn_up: TButton;
btn_down: TButton;
btn_delete: TButton;
NMFTP1: TNMFTP;
sdg_local: TSaveDialog;
procedure btn_closeClick(Sender: TObject);
procedure btn_connectClick(Sender: TObject);
procedure NMFTP1Connect(Sender: TObject);
procedure NMFTP1ListItem(Listing: String);
procedure lst_remoteClick(Sender: TObject);
procedure btn_downClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
m_host:string;
m_user:string;
m_pwd:string;
m_mode:integer;
name:string;
attr:string;
sign:string;
index:integer;
end;
var
main: Tmain;
implementation
{$R *.DFM}
procedure Tmain.btn_closeClick(Sender: TObject);
begin
close;
end;
procedure Tmain.btn_connectClick(Sender: TObject);
begin
dlgconnect.ShowModal;
// dlgconnect.edt_host.SetFocus;
end;
procedure Tmain.NMFTP1Connect(Sender: TObject);
begin
try
NMFTP1.ParseList:=true;
NMFTP1.Vendor := NMOS_AUTO;
lst_remote.Clear;
NMFTP1.List;
except
NMFTP1.Disconnect;
showmessage('connect is error');
end;
end;
procedure Tmain.NMFTP1ListItem(Listing: String);
begin
lst_remote.Items.Add(listing);
end;
procedure Tmain.lst_remoteClick(Sender: TObject);
begin
btn_down.Enabled:=true;
btn_delete.Enabled:=true;
index:=lst_remote.ItemIndex;
name:=nmftp1.FTPDirectoryList.name.Strings[index];
attr:=nmftp1.FTPDirectoryList.Attribute.strings[index];
sign:=copy(attr,0,1);
end;
procedure Tmain.btn_downClick(Sender: TObject);
begin
if attr='d' then
showmessage('Directory is not download');
if sdg_local.Execute then
begin
nmftp1.Download(name,sdg_local.FileName);
end;
end;
end.