最近在编写ftp
不过我现在只能用listbox
但是我想用listview之类的控件做,但是我不大清楚。
有没有人帮忙做一个ftp界面要跟cuteftp差不多的。基本功能能够实现
(删除,上传,下载,新建目录……)
也祝福天下父亲们快乐

解决方案 »

  1.   

    {******************************
    this is a works to show the normal FTP 
    ********************************}unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, OleServer, Outlook8, ExtCtrls, ComCtrls, Psock, NMFtp;type
      TForm1 = class(TForm)
        Label1: TLabel;
        edtAddress: TEdit;
        Label2: TLabel;
        edtPort: TEdit;
        btnConnect: TButton;
        btnDisconnect: TButton;
        btnDir: TButton;
        btnUpload: TButton;
        OpenDialog1: TOpenDialog;
        SaveDialog1: TSaveDialog;
        btnDownload: TButton;
        StatusBar1: TStatusBar;
        Bevel1: TBevel;
        NMFTP1: TNMFTP;
        edtDir: TEdit;
        btnChDir: TButton;
        Label5: TLabel;
        edtLocalFileName: TEdit;
        edtRemoteFileName: TEdit;
        btnRename: TButton;
        btnDelete: TButton;
        Label7: TLabel;
        Panel1: TPanel;
        ListBox1: TListBox;
        procedure FormCreate(Sender: TObject);
        procedure btnConnectClick(Sender: TObject);
        procedure btnDisconnectClick(Sender: TObject);
        procedure NMFTP1Connect(Sender: TObject);
        procedure NMFTP1Disconnect(Sender: TObject);
        procedure NMFTP1Success(Trans_Type: TCmdType);
        procedure NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
        procedure btnDirClick(Sender: TObject);
        procedure NMFTP1ListItem(Listing: String);
        procedure btnChDirClick(Sender: TObject);
        procedure btnUploadClick(Sender: TObject);
        procedure NMFTP1PacketSent(Sender: TObject);
        procedure btnDownloadClick(Sender: TObject);
        procedure NMFTP1PacketRecvd(Sender: TObject);
        procedure btnRenameClick(Sender: TObject);
        procedure btnDeleteClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
        //初始化
        edtAddress.Text:='166.111.168.18';
        edtPort.Text:='21';
        //ftp超时值
        NMFTP1.TimeOut:=2000;
        //编辑框属性
        edtLocalFileName.Text:='';
        edtRemoteFileName.Text:='';
        edtDir.Text:='';
    end;procedure TForm1.btnConnectClick(Sender: TObject);
    begin
      // 服务器信息
      NMFTP1.Host := edtAddress.Text;
      NMFTP1.Port := StrToInt(edtPort.Text);
      NMFTP1.UserID := 'anonymous';
      NMFTP1.Password := 'aa@aa.com';
      NMFTP1.Connect;
    end;procedure TForm1.btnDisconnectClick(Sender: TObject);
    begin
        NMFTP1.Disconnect;
    end;procedure TForm1.NMFTP1Connect(Sender: TObject);
    begin
        StatusBar1.SimpleText := '连接';
    end;procedure TForm1.NMFTP1Disconnect(Sender: TObject);
    begin
        StatusBar1.SimpleText := '断开连接';
    end;procedure TForm1.NMFTP1Success(Trans_Type: TCmdType);
    begin
      Case Trans_Type of
        cmdChangeDir: StatusBar1.SimpleText := 'ChangeDir操作成功';
        cmdMakeDir: StatusBar1.SimpleText := 'MakeDir操作成功';
        cmdDelete: StatusBar1.SimpleText := 'Delete操作成功';
        cmdRemoveDir: StatusBar1.SimpleText := 'RemoveDir操作成功';
        cmdList: StatusBar1.SimpleText := 'List操作成功';
        cmdRename: StatusBar1.SimpleText := 'Rename操作成功';
        cmdUpRestore: StatusBar1.SimpleText := 'UploadRestore操作成功';
        cmdDownRestore: StatusBar1.SimpleText := 'DownloadRestore操作成功';
        cmdDownload: StatusBar1.SimpleText := 'Download操作成功';
        cmdUpload: StatusBar1.SimpleText := 'Upload操作成功';
        cmdAppend: StatusBar1.SimpleText := 'UploadAppend操作成功';
        cmdReInit: StatusBar1.SimpleText := 'ReInit操作成功';
        cmdAllocate: StatusBar1.SimpleText := 'Allocate操作成功';
        cmdNList: StatusBar1.SimpleText := 'NList操作成功';
        cmdDoCommand: StatusBar1.SimpleText := 'DoCommand操作成功';
      end;
    end;procedure TForm1.NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
    begin
      Case Trans_Type of
        cmdChangeDir: StatusBar1.SimpleText := 'ChangeDir操作失败';
        cmdMakeDir: StatusBar1.SimpleText := 'MakeDir操作失败';
        cmdDelete: StatusBar1.SimpleText := 'Delete操作失败';
        cmdRemoveDir: StatusBar1.SimpleText := 'RemoveDir操作失败';
        cmdList: StatusBar1.SimpleText := 'List操作失败';
        cmdRename: StatusBar1.SimpleText := 'Rename操作失败';
        cmdUpRestore: StatusBar1.SimpleText := 'UploadRestore操作失败';
        cmdDownRestore: StatusBar1.SimpleText := 'DownloadRestore操作失败';
        cmdDownload: StatusBar1.SimpleText := 'Download操作失败';
        cmdUpload: StatusBar1.SimpleText := 'Upload操作失败';
        cmdAppend: StatusBar1.SimpleText := 'UploadAppend操作失败';
        cmdReInit: StatusBar1.SimpleText := 'ReInit操作失败';
        cmdAllocate: StatusBar1.SimpleText := 'Allocate操作失败';
        cmdNList: StatusBar1.SimpleText := 'NList操作失败';
        cmdDoCommand: StatusBar1.SimpleText := 'DoCommand操作失败';
      end;end;procedure TForm1.btnDirClick(Sender: TObject);
    begin
        //clear old info
        ListBox1.Items.Clear;
        //Dir
        try
            NMFTP1.List;
        except
            //error trap
        end;end;procedure TForm1.NMFTP1ListItem(Listing: String);
    begin
        //add dir
        ListBox1.Items.Add(Listing);
    end;procedure TForm1.btnChDirClick(Sender: TObject);
    begin
        //切换目录
        Try
            NMFTP1.ChangeDir(edtDir.Text);
        Except
        end;
    end;procedure TForm1.btnUploadClick(Sender: TObject);
    var
        localfname:string;
        remotefname:string;
    begin
        //上传文件
        if OpenDialog1.Execute then
            begin
                localfname:=OpenDialog1.FileName;
                // 获得本地上传的文件名
                edtLocalFileName.Text:=localfName;
                remotefname:=edtRemoteFileName.Text;
                if remotefname='' then
                    remotefname:=extractfilename(localfname);
                try
                    NMFTP1.Upload(localfname, remotefname);
                except
                end;
            end;
    end;procedure TForm1.NMFTP1PacketSent(Sender: TObject);
    begin
        //显示上传进度
        StatusBar1.SimpleText :=
            inttostr(round((NMFTP1.BytesSent/NMFTP1.BytesTotal)*100))+'%';
    end;procedure TForm1.btnDownloadClick(Sender: TObject);
    var
        localfname:string;
        remotefname:string;
    begin
        if SaveDialog1.Execute then
            begin
                localfname:=SaveDialog1.FileName;
                edtLocalFileName.Text:=localfname;
                remotefname:=edtRemoteFileName.Text;
                if remotefname='' then
                    exit;
                try
                    NMFTP1.Download(remotefname, localfname);
                except
                end;
            end;
    end;procedure TForm1.NMFTP1PacketRecvd(Sender: TObject);
    begin
        StatusBar1.SimpleText :=
            inttostr((Round((NMFTP1.BytesRecvd/NMFTP1.BytesTotal)*100)))+'%';
    end;procedure TForm1.btnRenameClick(Sender: TObject);
    var
        sourfname:string;
        dentfname:string;
    begin
        sourfname:=edtLocalFileName.Text;
        if sourfname='' then
            exit;
        dentfname:=edtRemoteFileName.Text;
        if dentfname='' then
            exit;
        try
            NMFTP1.Rename(sourfname, dentfname);
        except
        end;
    end;procedure TForm1.btnDeleteClick(Sender: TObject);
    var
        remotefname:string;
    begin
        //删除操作
        remotefname:=edtRemoteFileName.Text;
        if remotefname='' then
            exit;
        try
            NMFTP1.Delete(remotefname);
        except
        end;
    end;end.
      

  2.   

    楼上的给的是跟delphi自带的差不多阿。这个我当然知道了。。我要做的不是用listbox做的阿。
    界面要跟cuteftp差不多的。用listview阿。。listbox的我也会阿。
      

  3.   

    不要再用NM了
    使用Indy的比较好,Indy自带Demo包括了FTP的例子,有listview的,自己去研究了
    在Indy的官方网站下载了我的LYFTP -- LY FTP Explorer就是使用Indy编写的
    by http://lysoft.7u7.net