您的位置:首页 > 编程语言

一个简单FTP程序的主要源代码

2006-08-01 17:24 495 查看
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdFTP, Menus, FileCtrl, ExtCtrls, ComCtrls,ShellApi,IniFiles;
const
WM_BARICON=WM_USER+200;
type
TForm1 = class(TForm)
IdFTP1: TIdFTP;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
GroupBox1: TGroupBox;
conn_status: TLabel;
Timer1: TTimer;
SaveDialog1: TSaveDialog;
Label7: TLabel;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
UserIDEdit: TEdit;
PasswordEdit: TEdit;
FtpServerEdit: TEdit;
conn_btn: TButton;
Button2: TButton;
portedit: TEdit;
Label9: TLabel;
GroupBox2: TGroupBox;
exec_btn: TButton;
sjjg: TEdit;
Label10: TLabel;
Label11: TLabel;
UpDown1: TUpDown;
Label4: TLabel;
dirname: TEdit;
Label5: TLabel;
LocalPath: TEdit;
Button5: TButton;
N3: TMenuItem;
N7: TMenuItem;
downloadtitle: TLabel;
Label6: TLabel;
N8: TMenuItem;
Label8: TLabel;
Label12: TLabel;
file1: TEdit;
file2: TEdit;
Label13: TLabel;
jymin: TEdit;
UpDown2: TUpDown;
Label14: TLabel;
Label15: TLabel;
jyto: TEdit;
Button1: TButton;
Label16: TLabel;
jyhname1: TEdit;
Label17: TLabel;
jyhname2: TEdit;
N10: TMenuItem;
WINRAR1: TMenuItem;
downloadtitle2: TLabel;
procedure N2Click(Sender: TObject);
procedure conn_btnClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure exec_btnClick(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
procedure FtpServerEditKeyPress(Sender: TObject; var Key: Char);
procedure porteditKeyPress(Sender: TObject; var Key: Char);
procedure UserIDEditKeyPress(Sender: TObject; var Key: Char);
procedure PasswordEditKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure FTP1Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure N10Click(Sender: TObject);
procedure WINRAR1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure IdFTP1Disconnected(Sender: TObject);
procedure N5Click(Sender: TObject);

private
procedure copyfile(Const sourcefilename, targetfilename: String);
procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
procedure WMBarIcon(var Message:TMessage);message WM_BARICON;
procedure down_file(); //下载不是0时的文件
procedure Down_File_0s(); //下载是0时的文件
procedure Jy_File(); //解压不是0时的文件
procedure Jy_File_0s(); //解压是0时的文件
{ Private declarations }
public
exec_switch,conn_switch,quit_conn_switch:integer;//程序开执行的开关,1执行0不执行
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses unit2,unit3,unit4,parameter_unit;
{$R *.dfm}

procedure TForm1.WMSysCommand
(var Message:TMessage);
var
lpData:PNotifyIconData;
begin
if Message.WParam = SC_ICON then
begin
//如果用户最小化窗口则将窗口
//隐藏并在任务栏上添加图标
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
//SizeOf(PNotifyIconDataA);
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON
or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
Form1.Visible := False;
end
else
begin
//如果是其它的SystemCommand
//消息则调用系统缺省处理函数处理之。
DefWindowProc(Form1.Handle,Message.
Msg,Message.WParam,Message.LParam);
end;
//
end;

procedure TForm1.WMBarIcon(var Message:TMessage);
var
lpData:PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) then
begin
//如果用户点击任务栏图标则将图标删除并回复窗口。
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
Form1.Visible := True;
end;
end;
//以上是最小化到任务栏,只显图标的二个东西
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.conn_btnClick(Sender: TObject);
var
myinifile:Tinifile;
inifilename:string;
begin

//把设置保存到INI文件
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
myinifile.WriteString('ftp_conn','host',ftpserveredit.Text);
myinifile.WriteString('ftp_conn','port',portedit.Text);
myinifile.WriteString('ftp_conn','username',useridedit.Text);
myinifile.WriteString('ftp_conn','password',passwordedit.Text);
//加一个如果连接超时
if idftp1.Connected then
begin
showmessage('已连接上!');
end
else
begin
conn_status.Caption:='正在连接...';
application.ProcessMessages;
with IdFTP1 do
try
if UserIDEdit.Text<>'' then
begin
Username := UserIDEdit.Text;
end;
if PasswordEdit.Text<>'' then
begin
Password := PasswordEdit.Text;
end;
if portedit.Text<>'' then Port:=strtoint(portedit.text);
Host:= FtpServerEdit.Text;
Connect;
conn_switch:=1; //连接上为1
conn_status.Caption:='已连接FTP服务器:'+FtpServerEdit.Text;
finally
conn_status.Caption:='连接失败!';
end;

end;

end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if conn_switch=1 then
begin
conn_status.Caption:='连接已断开';
quit_conn_switch:=1;
conn_switch:=0;
idftp1.Quit;
end;
end;

procedure TForm1.exec_btnClick(Sender: TObject);
var
myinifile:Tinifile;
inifilename:string;
begin
if idftp1.Connected then
begin
//把设置保存到INI文件
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
myinifile.WriteString('canshu','sjjg',sjjg.Text);
myinifile.WriteString('canshu','jysj',jymin.Text);
myinifile.WriteString('canshu','jyto',jyto.Text);
myinifile.WriteString('canshu','mulu_server',dirname.Text);
myinifile.WriteString('canshu','localpath',localpath.Text);
myinifile.WriteString('canshu','file1qz',file1.Text);
myinifile.WriteString('canshu','file2qz',file2.Text);
myinifile.WriteString('canshu','jyhfile1_name',jyhname1.Text);
myinifile.WriteString('canshu','jyhfile2_name',jyhname2.Text);
myinifile.Free;
IdFTP1.ChangeDir(dirname.Text); //转目录到dirname中定义的。
if exec_switch=0 then
begin
exec_switch:=1;
//showmessage(inttostr(exec_switch));//打开执行开关
exec_btn.Caption:='暂停执行';
end
else
begin
exec_switch:=0;
// showmessage(inttostr(exec_switch));//打开执行开关
exec_btn.Caption:='应用设置并执行';
end;
end
else
begin
showmessage('还没有连接FTP服务器!');
end;

end;

procedure TForm1.Button5Click(Sender: TObject);
var
s:string;
begin
if SelectDirectory('请选择一个目录', '', s) then
begin
if s[Length(s)] <> '/' then
s := s + '/';
localpath.Text:=s;
end;

//if savedialog1.Execute then
// LocalPath.Text:=savedialog1.FileName;
end;

procedure TForm1.N7Click(Sender: TObject);
begin
if conn_switch=1 then
begin
conn_status.Caption:='连接已断开';
quit_conn_switch:=1;
showmessage(inttostr(quit_conn_switch));
idftp1.Quit;
end;
end;

procedure TForm1.down_file(); //此过程用过下载不是0时的文件
var
muluname_server,filename_server1,filename_server2,filename1,filename2:string;
begin
try
muluname_server:=FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now);
filename_server1:=file1.text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';
filename_server2:=file2.Text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';

downloadtitle.Caption:='正在下载文件:'+muluname_server+'/'+filename_server1;
downloadtitle2.Caption:='正在下载文件:'+muluname_server+'/'+filename_server2;
application.ProcessMessages;
//showmessage(filename_server);
if not DirectoryExists(localpath.Text+muluname_server) then
begin
CreateDirectory(PChar(localpath.Text+muluname_server),nil);
end;

IdFTP1.ChangeDir(muluname_server); //首先进入到要拷贝的目录
try
IdFTP1.Get(filename_server1,LocalPath.Text+muluname_server+'/'+filename_server1,true);
IdFTP1.Get(filename_server2,LocalPath.Text+muluname_server+'/'+filename_server2,true);
finally
end;
IDfTP1.ChangeDirUp; //回到上一级目录

except
end;
end;

procedure TForm1.Down_File_0s();
var
muluname_server,filename_server1,filename_server2,filename1,filename2:string;
begin
try
muluname_server:=FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1);
filename_server1:=file1.text+FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1)+'23'+'.Z';
filename_server2:=file2.Text+FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1)+'23'+'.Z';

downloadtitle.Caption:='正在下载文件:'+muluname_server+'/'+filename_server1;
downloadtitle2.Caption:='正在下载文件:'+muluname_server+'/'+filename_server2;
application.ProcessMessages;
//showmessage(filename_server);
if not DirectoryExists(localpath.Text+muluname_server) then
begin
CreateDirectory(PChar(localpath.Text+muluname_server),nil);
end;

IdFTP1.ChangeDir(muluname_server); //首先进入到要拷贝的目录
try
IdFTP1.Get(filename_server1,LocalPath.Text+muluname_server+'/'+filename_server1,true);
IdFTP1.Get(filename_server2,LocalPath.Text+muluname_server+'/'+filename_server2,true);
finally
end;
IDfTP1.ChangeDirUp; //回到上一级目录
except
end;
end;

procedure TForm1.Jy_File(); //解压不是0时时的文件
var
myinifile:Tinifile;
inifilename,winrarpath:string;
muluname_server,filename_server1,filename_server2,filename1,filename2:string;
//解压用的变量
s,s1: String;
StartupInfo,StartupInfo1:TStartUpInfo;
ProcessInfo,ProcessInfo1:TProcessInformation;
begin
try
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
//WINRAR路径参数设置
winrarpath:=myinifile.ReadString('parameter','winrar_path','');
myinifile.Free;

muluname_server:=FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now);
filename_server1:=file1.text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';
filename_server2:=file2.Text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';
filename1:=file1.text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1);//解压后的文件一名
filename2:=file2.Text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1);//解压后的文件二名 注意:当前小时下载前一小时的文件。

downloadtitle.Caption:='正在解压文件:'+muluname_server+'/'+filename_server1;
downloadtitle2.Caption:='正在解压文件:'+muluname_server+'/'+filename_server2;
application.ProcessMessages;
//开始解压
//加压缩s:= 'D:/Program Files/WINRAR/winrar a -ep e:/p/B.RAR e:/p/*.txt';
s:= winrarpath+' x '+LocalPath.Text+muluname_server+'/'+filename_server1+' '+LocalPath.Text+muluname_server;
//Log.Lines.Append(s);
FillChar(ProcessInfo, sizeof(TProcessInformation), 0);
FillChar(StartupInfo, sizeof(TStartupInfo), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
if CreateProcess(nil,PChar(s),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,StartUpInfo,ProcessInfo)
then
begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
//ShowMessage('程序完毕!');
end
else
begin
MessageBox(0,'调用WinRAR失败,请检查WinRAR程序!','提示',64);
Exit;
end;
//解压完毕
s1:= winrarpath+' x '+LocalPath.Text+muluname_server+'/'+filename_server2+' '+LocalPath.Text+muluname_server;
FillChar(ProcessInfo1, sizeof(TProcessInformation), 0);
FillChar(StartupInfo1, sizeof(TStartupInfo), 0);
StartupInfo1.cb := SizeOf(TStartupInfo);
if CreateProcess(nil,PChar(s1),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,StartUpInfo1,ProcessInfo1)
then
begin
WaitForSingleObject(ProcessInfo1.hProcess, INFINITE);
CloseHandle(ProcessInfo1.hProcess);
//ShowMessage('程序完毕!');
end
else
begin
MessageBox(0,'调用WinRAR失败,请检查WinRAR程序!','提示',64);
Exit;
end;
//解压完毕,把解压后的文件COPY到SQL要读取的文件夹
copyfile(localpath.Text+muluname_server+'/'+filename1,jyto.Text+jyhname1.Text+'.txt');
copyfile(localpath.Text+muluname_server+'/'+filename2,jyto.Text+jyhname2.Text+'.txt');
except
end;
end;

procedure TForm1.Jy_File_0s(); //解压是0时时的文件
var
myinifile:Tinifile;
inifilename,winrarpath:string;
muluname_server,filename_server1,filename_server2,filename1,filename2:string;
//解压用的变量
s,s1: String;
StartupInfo,StartupInfo1:TStartUpInfo;
ProcessInfo,ProcessInfo1:TProcessInformation;
begin
try
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
//WINRAR路径参数设置
winrarpath:=myinifile.ReadString('parameter','winrar_path','');
myinifile.Free;

muluname_server:=FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1);
filename_server1:=file1.text+FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1)+'23'+'.Z';
filename_server2:=file2.Text+FormatDateTime('yyyy',now()-1)+FormatDateTime('mm',now()-1)+FormatDateTime('dd',now()-1)+'23'+'.Z';
filename1:=file1.text+FormatDateTime('yyyy',now-1)+FormatDateTime('mm',now-1)+FormatDateTime('dd',now-1)+'23';//解压后的文件一名
filename2:=file2.Text+FormatDateTime('yyyy',now-1)+FormatDateTime('mm',now-1)+FormatDateTime('dd',now-1)+'23';//解压后的文件二名 注意:当前小时下载前一小时的文件。

downloadtitle.Caption:='正在解压文件:'+muluname_server+'/'+filename_server1;
downloadtitle2.Caption:='正在解压文件:'+muluname_server+'/'+filename_server2;
application.ProcessMessages;
//开始解压
//加压缩s:= 'D:/Program Files/WINRAR/winrar a -ep e:/p/B.RAR e:/p/*.txt';
s:= winrarpath+' x '+LocalPath.Text+muluname_server+'/'+filename_server1+' '+LocalPath.Text+muluname_server;
//Log.Lines.Append(s);
FillChar(ProcessInfo, sizeof(TProcessInformation), 0);
FillChar(StartupInfo, sizeof(TStartupInfo), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
if CreateProcess(nil,PChar(s),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,StartUpInfo,ProcessInfo)
then
begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
//ShowMessage('程序完毕!');
end
else
begin
MessageBox(0,'调用WinRAR失败,请检查WinRAR程序!','提示',64);
Exit;
end;
//解压完毕
s1:= winrarpath+' x '+LocalPath.Text+muluname_server+'/'+filename_server2+' '+LocalPath.Text+muluname_server;
FillChar(ProcessInfo1, sizeof(TProcessInformation), 0);
FillChar(StartupInfo1, sizeof(TStartupInfo), 0);
StartupInfo1.cb := SizeOf(TStartupInfo);
if CreateProcess(nil,PChar(s1),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,StartUpInfo1,ProcessInfo1)
then
begin
WaitForSingleObject(ProcessInfo1.hProcess, INFINITE);
CloseHandle(ProcessInfo1.hProcess);
//ShowMessage('程序完毕!');
end
else
begin
MessageBox(0,'调用WinRAR失败,请检查WinRAR程序!','提示',64);
Exit;
end;
//解压完毕,把解压后的文件COPY到SQL要读取的文件夹
copyfile(localpath.Text+muluname_server+'/'+filename1,jyto.Text+jyhname1.Text+'.txt');
copyfile(localpath.Text+muluname_server+'/'+filename2,jyto.Text+jyhname2.Text+'.txt');
except
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
muluname_server,filename_server1,filename_server2,filename1,filename2:string;
//解压用的变量
s,s1: String;
StartupInfo,StartupInfo1:TStartUpInfo;
ProcessInfo,ProcessInfo1:TProcessInformation;
begin
if exec_switch=1 then //如果执行开关没有打开就不能执行
begin
//定义目录名,文件一名,文件二名。
muluname_server:=FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now);
filename_server1:=file1.text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';
filename_server2:=file2.Text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1)+'.Z';
filename1:=file1.text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1);//解压后的文件一名
filename2:=file2.Text+FormatDateTime('yyyy',now)+FormatDateTime('mm',now)+FormatDateTime('dd',now)+inttostr(strtoint(FormatDateTime('hh',now))-1);//解压后的文件二名 注意:当前小时下载前一小时的文件。
//如果连接断开就连接上
if not idftp1.Connected then
begin
idftp1.Connect;
idftp1.Noop;
conn_status.Caption:='已连接FTP服务器:'+FTPServerEdit.Text;
end;
//下载文件

if idftp1.Connected then
begin
if strtoint(copy(datetimetostr(now()),15,2))=strtoint(sjjg.Text) then
begin
if strtoint(FormatDateTime('hh',now))=0 then
begin
Down_File_0s(); //下载0时时的文件
end
else
begin
Down_File(); //下载不是0时时的文件过程
end;
end;
end;
//解压
if strtoint(copy(datetimetostr(now()),15,2))=strtoint(jymin.Text) then
begin
if strtoint(formatDateTime('hh',now))=0 then
begin
Jy_File_0s(); //解压是0时时的文件
end
else
begin
Jy_File(); //解压不是0时时的文件
end;
end;
downloadtitle.Caption:='没有文件在下载或解压';
downloadtitle2.Caption:='没有文件在下载或解压';
end;
end;

//copy file's procedure
Procedure TForm1.copyfile( Const sourcefilename, targetfilename: String );
Var
S, T: TFileStream;
Begin
S := TFileStream.Create( sourcefilename, fmOpenRead );
try
T := TFileStream.Create( targetfilename,fmOpenWrite or fmCreate);
try
T.CopyFrom(S, S.Size ) ;
finally
T.Free;
end;
finally
S.Free;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
myinifile:Tinifile;
inifilename:string;
hh,mm,ss,ms:Word;

begin
form1.Icon.LoadFromFile('img/logo.ico'); //加载系统图标
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
//连接FTP服务器参数设置
ftpserveredit.Text:=myinifile.ReadString('ftp_conn','host','');
portedit.Text:=myinifile.ReadString('ftp_conn','port','');
UserIDEdit.Text:=myinifile.ReadString('ftp_conn','username','');
PasswordEdit.Text:=myinifile.ReadString('ftp_conn','password','');
//参数设置
updown1.Position:=strtoint(myinifile.ReadString('canshu','sjjg',''));
updown2.Position:=strtoint(myinifile.ReadString('canshu','jysj',''));
jyto.Text:=myinifile.ReadString('canshu','jyto','');
localpath.Text:=myinifile.ReadString('canshu','localpath','');
dirname.Text:=myinifile.ReadString('canshu','mulu_server','');
file1.Text:=myinifile.ReadString('canshu','file1qz','');
file2.Text:=myinifile.ReadString('canshu','file2qz','');
jyhname1.Text:=myinifile.ReadString('canshu','jyhfile1_name','');
jyhname2.Text:=myinifile.ReadString('canshu','jyhfile2_name','');

myinifile.Free;

timer1.Interval:=60000;//60秒刷新一次
exec_switch:=0; //初始状态执行开关不打开
downloadtitle.Caption:='';
downloadtitle2.Caption:='';
end;

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
sjjg.Text:=inttostr(self.updown1.Position);
end;

procedure TForm1.FtpServerEditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
portedit.SetFocus;
end;

procedure TForm1.porteditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
useridedit.SetFocus;
end;

procedure TForm1.UserIDEditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
passwordedit.SetFocus;
end;

procedure TForm1.PasswordEditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
conn_btn.SetFocus;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
if SelectDirectory('请选择一个目录', '', s) then
begin
if s[Length(s)] <> '/' then
s := s + '/';
jyto.Text:=s;
end;
end;

procedure TForm1.FTP1Click(Sender: TObject);
begin
if not idftp1.Connected then
begin
showmessage('还没有连接FTP服务器');
end
else
form2.ShowModal;
end;

procedure TForm1.N6Click(Sender: TObject);
begin
about.ShowModal;
end;

procedure TForm1.N9Click(Sender: TObject);
begin
sg_down.ShowModal;
end;

procedure TForm1.N10Click(Sender: TObject);
begin
parameter.ShowModal;
end;

procedure TForm1.WINRAR1Click(Sender: TObject);
var
spath:string;
begin
if(MessageBox(handle,'确定要安装winrar软件吗?','提 示',mb_IconInformation+mb_YesNo)=mryes) then
begin
sPath:=ExtractFilePath(application.ExeName);
ShellExecute(Handle, 'open', PChar(''+sPath+'winrar342.exe'), nil, nil, SW_SHOW);
end;
end;

procedure TForm1.N3Click(Sender: TObject);
var
myinifile:Tinifile;
inifilename:string;
begin

//把设置保存到INI文件
inifilename:=ExtractFilePath(Paramstr(0))+'config.ini';
myinifile:=Tinifile.Create(inifilename);
myinifile.WriteString('ftp_conn','host',ftpserveredit.Text);
myinifile.WriteString('ftp_conn','port',portedit.Text);
myinifile.WriteString('ftp_conn','username',useridedit.Text);
myinifile.WriteString('ftp_conn','password',passwordedit.Text);
//加一个如果连接超时
if idftp1.Connected then
begin
showmessage('已连接上!');
end
else
begin
conn_status.Caption:='正在连接...';
application.ProcessMessages;
with IdFTP1 do
try
if UserIDEdit.Text<>'' then
begin
Username := UserIDEdit.Text;
end;
if PasswordEdit.Text<>'' then
begin
Password := PasswordEdit.Text;
end;
Host:= FtpServerEdit.Text;
Port:=strtoint(portedit.text);
Connect;
conn_switch:=1; //连接上为1
conn_status.Caption:='已连接FTP服务器:'+FtpServerEdit.Text;
finally
//showmessage('请检查主机地址,端口号,用户名,密码是否正确!');
end;

end;

end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
try
if Application.MessageBox('确定退出本软件吗?','询问',MB_OKCANCEL+MB_ICONQUESTION)=IDOK then
begin
CanClose:=True;
end
else
CanClose:=False;
except
Exit;
end;
end;

procedure TForm1.IdFTP1Disconnected(Sender: TObject);
begin

//if (conn_switch=1) then
// begin
//if (quit_conn_switch<>1) then
//begin
idftp1.Connect;
conn_status.Caption:='已连接FTP服务器:'+ftpserveredit.Text;
//end;
//end;
end;

procedure TForm1.N5Click(Sender: TObject);
var
sPath:string;
begin
sPath:=ExtractFilePath(application.ExeName);
ShellExecute(Handle, 'open', PChar(''+sPath+'ftp_help.chm'), nil, nil, SW_SHOW);
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: