FTPClientUnit.pas
资源名称:FTPClient.rar [点击查看]
上传用户:yzhui7711
上传日期:2021-12-23
资源大小:293k
文件大小:3k
源码类别:
Ftp客户端
开发平台:
Delphi
- unit FTPClientUnit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, ComCtrls, Menus, StdCtrls, ShellAPI, FileListExplorer,
- CustomFileSystem, FTPFileSystem, FolderTreeExplorer, LocalFileSystem,
- FileSystemBrowseDialog, FileSystemSaveDialog, FTPLoginDialog;
- type
- TFTPClientForm = class(TForm)
- FolderTreeExplorer1: TFolderTreeExplorer;
- FileListExplorer1: TFileListExplorer;
- FTPFileSystem1: TFTPFileSystem;
- Splitter1: TSplitter;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Connect1: TMenuItem;
- Disconnect1: TMenuItem;
- StatusBar1: TStatusBar;
- PopupMenu1: TPopupMenu;
- DownloadFile1: TMenuItem;
- Openfile1: TMenuItem;
- LocalFileSystem1: TLocalFileSystem;
- FileSystemSaveDialog1: TFileSystemSaveDialog;
- FTPLoginDialog1: TFTPLoginDialog;
- procedure Connect1Click(Sender: TObject);
- procedure Disconnect1Click(Sender: TObject);
- procedure FTPFileSystem1Echo(Sender: TObject; EchoStr: String);
- procedure PopupMenu1Popup(Sender: TObject);
- procedure DownloadFile1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Openfile1Click(Sender: TObject);
- procedure FileListExplorer1DblClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FTPClientForm: TFTPClientForm;
- implementation
- {$R *.dfm}
- procedure TFTPClientForm.Connect1Click(Sender: TObject);
- begin
- if not FTPFileSystem1.Connected then
- FTPFileSystem1.Connect;
- end;
- procedure TFTPClientForm.Disconnect1Click(Sender: TObject);
- begin
- if FTPFileSystem1.Connected then
- FTPFileSystem1.DisConnect;
- end;
- procedure TFTPClientForm.FTPFileSystem1Echo(Sender: TObject;
- EchoStr: String);
- begin
- StatusBar1.SimpleText:=EchoStr;
- end;
- procedure TFTPClientForm.PopupMenu1Popup(Sender: TObject);
- begin
- DownloadFile1.Enabled:=(FileListExplorer1.SelCount=1) and not FileListExplorer1.Selected.Descriptor.Folder;
- Openfile1.Enabled:=DownloadFile1.Enabled;
- end;
- procedure TFTPClientForm.DownloadFile1Click(Sender: TObject);
- var
- f:TFileStream;
- s:string;
- begin
- with FileSystemSaveDialog1 do
- if Execute then begin
- s:=CurrentDirectory+FileName;
- s:=Copy(s,2,Length(s)-1);
- f:=TFileStream.Create(s,fmOpenWrite or fmCreate);
- f.Size:=0;
- FTPFileSystem1.ReadStreamFromFile(FileListExplorer1.Selected.Descriptor.FilePath+FileListExplorer1.Selected.Descriptor.FileName,f);
- f.Destroy;
- end;
- end;
- procedure TFTPClientForm.FormCreate(Sender: TObject);
- begin
- PopupMenu1.Items.Caption:='File';
- end;
- procedure TFTPClientForm.Openfile1Click(Sender: TObject);
- var
- f:TFileStream;
- s:array[0..MAX_PATH] of Char;
- t:string;
- SEI:TShellExecuteInfo;
- begin
- GetTempPath(MAX_PATH,@s[0]);
- t:=s+FileListExplorer1.Selected.Descriptor.FileName;
- f:=TFileStream.Create(t,fmOpenWrite or fmCreate);
- f.Size:=0;
- FTPFileSystem1.ReadStreamFromFile(FileListExplorer1.Selected.Descriptor.FilePath+FileListExplorer1.Selected.Descriptor.FileName,f);
- f.Destroy;
- ZeroMemory(@SEI,SizeOf(SEI));
- SEI.cbSize:=SizeOf(SEI);
- SEI.lpFile:=PChar(t);
- SEI.nShow:=SW_SHOWNORMAL;
- Assert(ShellExecuteEx(@SEI),SysErrorMessage(GetLastError));
- end;
- procedure TFTPClientForm.FileListExplorer1DblClick(Sender: TObject);
- begin
- if (FileListExplorer1.SelCount=1) and not FileListExplorer1.Selected.Descriptor.Folder then
- Openfile1Click(nil);
- end;
- end.