求用多线程实现ftp下载的例子
解决方案 »
- class reference type是个什么东西?
- opos 打印机缓冲区的问题
- 关于goto 语句
- 我下载了个程序,需要winskinform单元,是什么控件呢?我安装了vclskinform的
- 求助:怎样在运行时根据需要确定是否执行事件过程?
- 我的Delphi7这是怎么了????各位高手来看看啊,求救!~~~~
- 如何在程序中,实现生成一个.exe文件?
- 怎样解决用ado连接access库的路径问题!
- 请问如果读取本机硬盘上存的cookie, 比如如 sina的cookie?
- 我要用矩形框透明填充图象类bmp中某一矩形区域怎么办?
- 初学delphi,如何用ASCII码把字符串abcdefg变成bcdefgh?
- IRegex 这个类是个什么东东
Classes, SysUtils, Windows, Forms, NMFTP;Type
TFtpDown = Class(TThread)
private
FAddr:String;
FRemotePath:String;
FLocalFile:String;
FRemoteFile:String;
FUser:String;
FPswd:String;
FPort:Integer;
FTimeout:Integer;
FNMFTP: TNMFTP;
protected
Procedure Execute;override;
Public
Constructor Create(sAddr,sRemotePath,sRemoteFile,sLocalFile,
sUser,sPswd:String; iPort,iTimeout:Integer);
end;Procedure FtpDown(sAddr,sRemotePath,sRemoteFile,sLocalFile,sUser,sPswd:String;
iPort,iTimeout:Integer);
//用线程下载指定的FTP文件
//sAddr:服务器的地址
//sRemotePath:远程服务器的文件路径
//sRemoteFile:要下载的文件,注意,文件名区分大小写
//sLocalFile:本地文件名称
//sUser:帐号
//sPswd:密码
//iPort:服务器所用的端口
//iTimeOut:超时时间,单位:秒
//调用例子:FtpDown('192.168.0.1','/','test.txt','c:\test.txt','user','pswd',21,300);implementationProcedure FtpDown(sAddr,sRemotePath,sRemoteFile,sLocalFile,sUser,sPswd:String;
iPort,iTimeout:Integer);
begin
TFtpDown.Create(sAddr,sRemotePath,sRemoteFile,sLocalFile,sUser,sPswd,iPort,iTimeout);
end;{ TFtpDown }constructor TFtpDown.Create(sAddr,sRemotePath,sRemoteFile,sLocalFile,
sUser,sPswd:String; iPort,iTimeout:Integer);
begin
Inherited Create(true); FAddr:=sAddr;
FRemotePath:=sRemotePath;
FLocalFile:=Trim(sLocalFile);
FRemoteFile:=sRemoteFile;
FUser:=sUser;
FPswd:=sPswd;
FPort:=iPort;
FTimeout:=iTimeout;
FNMFTP:=TNMFTP.Create(nil);
FreeOnTerminate:=true; Resume;
end;procedure TFtpDown.Execute;
begin
try
FNMFTP.Host:=FAddr;
FNMFTP.UserID:=FUser;
FNMFTP.Password:=FPswd;
FNMFTP.Port:=FPort;
FNMFTP.TimeOut:=FTimeout*1000;
try
FNMFTP.Connect;
if FRemotePath>'' then
FNMFtp.ChangeDir(FRemotePath);
FNMFtp.Mode(Mode_Byte);
FNMFTP.Download(FRemoteFile,FLocalFile);
FNMFTP.Disconnect;
except
end;
finally
FNMFTP.Free;
end;
end;end.