📄 wlftp.~pas
字号:
unit WLFtp;
interface
uses
Windows, Messages, Variants,SysUtils, Classes, Wininet, Dialogs;
type
TWLFtp=class(TObject)
public
InetHandle:HInternet; // 句柄
FtpHandle:HInternet; // 句柄
Host:string; // 主机IP地址
UserName:string; // 用户名
Password:string; // 密码
Port:integer; // 端口
constructor Create;overload;
constructor Create(hst,user,pw:string;prt:integer);overload;
function Connect: boolean;
function Disconnect: boolean;
function UploadFile(RemoteFile: PChar; NewFile: PChar): boolean;
function DownloadFile(RemoteFile: PChar; NewFile: PChar): boolean;
end;
implementation
//-------------------------------------------------------------------------
constructor TWLFtp.Create; // 构造函数
begin
inherited Create;host:='127.0.0.1';Port:=21;
UserName:='smtmg';Password:='19961205';
end;
constructor TWLFtp.Create(hst,user,pw:string;prt:integer); // 构造函数
begin
inherited Create;host:=hst;Port:=prt;
UserName:=user;Password:=pw;
end;
function TWLFtp.Connect:boolean; //链接服务器
begin
try
Result:=false; // 创建句柄
InetHandle:=InternetOpen(PChar('KOLFTP'), 0, nil, nil, 0);
FtpHandle:=InternetConnect(InetHandle,PChar(Host),Port,PChar(UserName),
PChar(Password),INTERNET_SERVICE_FTP,0,255);
if Assigned(FtpHandle) then Result:=true;
except
Result:=false;
end;
end;
function TWLFtp.Disconnect: boolean;
begin //断开链接
try
InternetCloseHandle(FtpHandle);
InternetCloseHandle(InetHandle);
FtpHandle:=nil;inetHandle:=nil;
Result:=true;
except
Result:=false;
end;
end;
function TWLFtp.UploadFile(RemoteFile:PChar;NewFile:PChar): boolean;
begin// 上传文件
try
Result:=true;//FTPMakeDirectory(NewFile);
if not FtpPutFile(FtpHandle,RemoteFile,NewFile,FTP_TRANSFER_TYPE_BINARY,255) then
Result:=false;
except
Result:=false;
end;
end;
function TWLFtp.DownloadFile(RemoteFile: PChar; NewFile: PChar): boolean;
begin// 下载文件
try
Result:=true;//MakeDirectory(NewFile);
if not FtpGetFile(FtpHandle,RemoteFile,NewFile,
True,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY OR INTERNET_FLAG_RELOAD,255) then
Result:=false;
except
Result:=false;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -