我正在做自动下载的程序,不过是下载大量的图片。你可以用nmftp,indy或者wininet中的函数自己写。给你一个wininet的例子。 function TForm1.GetList(ip:string):bool; //得到远程抓拍机内的文件名列表 var hNet, hFTP,hFind: HINTERNET; bSuccess: Boolean; FindData: TWin32FindData; begin //timer1.Enabled:=true; //control := true; hNet := InternetOpen('Program_Name', // Agent INTERNET_OPEN_TYPE_PRECONFIG, // AccessType nil, // ProxyName nil, // ProxyBypass 0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE if hNet = nil then begin memo1.Lines.Add('缺少动态连接库WinInet.Dll!'); Result := False; Exit; end; timer1.Enabled:=true; application.ProcessMessages(); { Connect to the FTP Server } hFTP := InternetConnect(hNet, // Handle from InternetOpen pchar('192.168.0.253'), // FTP server 21, // (INTERNET_DEFAULT_FTP_PORT), PChar('root'), // username PChar(''), // password INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher? 0, // flag: 0 or INTERNET_FLAG_PASSIVE 255);// User defined number for callback if hFTP = nil then begin InternetCloseHandle(hNet); memo1.Lines.Add('连接'+ip+'成功!准备开始下载!'); Result := False; Exit; end; timer1.Enabled :=false; { Change directory } //timer1.Enabled:=true; bSuccess := FtpSetCurrentDirectory(hFTP, PChar('/mnt/imagefolder')); if not bSuccess then begin InternetCloseHandle(hFTP); InternetCloseHandle(hNet); memo1.Lines.Add('操作抓拍机错误,请检查!'); Result := False; Exit; end; timer1.Enabled:=false; hFind:= FtpFindFirstFile(hFtp, '*.jpg',FindData, 0, 0); if hFind = nil then begin memo1.lines.add('抓拍机内暂无图片!'); InternetCloseHandle(hFTP); InternetCloseHandle(hNet); Result:=false; Exit; end; str:=tstringlist.Create; str.Clear; while InternetFindnextFile(hFind, @FindData) do begin str.Add(FindData.cfilename); end; InternetCloseHandle(hFind); InternetCloseHandle(hFTP); InternetCloseHandle(hNet); Result := true;end;function TForm1.download(ReFile,LoFile,ip:string):Bool; var Hnet,Hftp:HINTERNET; bSuccess: Boolean; bGetFile: Boolean; begin hNet := InternetOpen('Program_Name', // Agent INTERNET_OPEN_TYPE_PRECONFIG, // AccessType nil, // ProxyName nil, // ProxyBypass 0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE if hNet = nil then begin memo1.Lines.Add('缺少动态连接库WinInet.Dll!'); Result := False; Exit; end; { Connect to the FTP Server } hFTP := InternetConnect(hNet, // Handle from InternetOpen PChar(ip), // FTP server 21, // (INTERNET_DEFAULT_FTP_PORT), PChar('root'), // username PChar(''), // password INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher? INTERNET_FLAG_PASSIVE, // flag: 0 or INTERNET_FLAG_PASSIVE 0);// User defined number for callback if hFTP = nil then begin InternetCloseHandle(hNet); memo1.Lines.add(ip+'不存在!'); Result := False; Exit; end; { Change directory } bSuccess := FtpSetCurrentDirectory(hFTP, PChar('/mnt/imagefolder')); if not bSuccess then begin InternetCloseHandle(hFTP); InternetCloseHandle(hNet); memo1.Lines.Add('操作错误,请检查!'); Result := False; Exit; end; memo1.Lines.Add('正在下载!'+ReFile); bGetFile:=ftpgetfile(hftp, PChar(ReFile), pchar(LoFile), false, File_Attribute_Normal, Ftp_Transfer_Type_Binary, 0); if not bGetFile then begin memo1.Lines.Add(ReFile+'下载失败!'); inc(ErrNum); InternetCloseHandle(hFTP); InternetCloseHandle(hNet); Result:=False; Exit; end; memo1.lines.add(ReFile+'下载成功!'); sleep(20); InternetCloseHandle(hFTP); InternetCloseHandle(hNet); end;procedure TForm1.FormCreate(Sender: TObject); begin ErrNum:=0; end;procedure TForm1.Timer1Timer(Sender: TObject); begin memo1.Lines.Add('操作失败!请检查!'); //control := false; //time := 0; exit;end;
function TForm1.GetList(ip:string):bool; //得到远程抓拍机内的文件名列表
var
hNet, hFTP,hFind: HINTERNET;
bSuccess: Boolean;
FindData: TWin32FindData;
begin
//timer1.Enabled:=true;
//control := true;
hNet := InternetOpen('Program_Name', // Agent
INTERNET_OPEN_TYPE_PRECONFIG, // AccessType
nil, // ProxyName
nil, // ProxyBypass
0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE
if hNet = nil then
begin
memo1.Lines.Add('缺少动态连接库WinInet.Dll!');
Result := False;
Exit;
end;
timer1.Enabled:=true;
application.ProcessMessages();
{ Connect to the FTP Server }
hFTP := InternetConnect(hNet, // Handle from InternetOpen
pchar('192.168.0.253'), // FTP server
21, // (INTERNET_DEFAULT_FTP_PORT),
PChar('root'), // username
PChar(''), // password
INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?
0, // flag: 0 or INTERNET_FLAG_PASSIVE
255);// User defined number for callback
if hFTP = nil then
begin
InternetCloseHandle(hNet);
memo1.Lines.Add('连接'+ip+'成功!准备开始下载!');
Result := False;
Exit;
end;
timer1.Enabled :=false; { Change directory }
//timer1.Enabled:=true;
bSuccess := FtpSetCurrentDirectory(hFTP, PChar('/mnt/imagefolder'));
if not bSuccess then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
memo1.Lines.Add('操作抓拍机错误,请检查!');
Result := False;
Exit;
end;
timer1.Enabled:=false; hFind:= FtpFindFirstFile(hFtp, '*.jpg',FindData, 0, 0);
if hFind = nil then
begin
memo1.lines.add('抓拍机内暂无图片!');
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Result:=false;
Exit;
end; str:=tstringlist.Create;
str.Clear;
while InternetFindnextFile(hFind, @FindData) do
begin
str.Add(FindData.cfilename);
end; InternetCloseHandle(hFind);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Result := true;end;function TForm1.download(ReFile,LoFile,ip:string):Bool;
var
Hnet,Hftp:HINTERNET;
bSuccess: Boolean;
bGetFile: Boolean;
begin
hNet := InternetOpen('Program_Name', // Agent
INTERNET_OPEN_TYPE_PRECONFIG, // AccessType
nil, // ProxyName
nil, // ProxyBypass
0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE
if hNet = nil then
begin
memo1.Lines.Add('缺少动态连接库WinInet.Dll!');
Result := False;
Exit;
end; { Connect to the FTP Server }
hFTP := InternetConnect(hNet, // Handle from InternetOpen
PChar(ip), // FTP server
21, // (INTERNET_DEFAULT_FTP_PORT),
PChar('root'), // username
PChar(''), // password
INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?
INTERNET_FLAG_PASSIVE, // flag: 0 or INTERNET_FLAG_PASSIVE
0);// User defined number for callback
if hFTP = nil then
begin
InternetCloseHandle(hNet);
memo1.Lines.add(ip+'不存在!');
Result := False;
Exit;
end; { Change directory }
bSuccess := FtpSetCurrentDirectory(hFTP, PChar('/mnt/imagefolder'));
if not bSuccess then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
memo1.Lines.Add('操作错误,请检查!');
Result := False;
Exit;
end; memo1.Lines.Add('正在下载!'+ReFile);
bGetFile:=ftpgetfile(hftp,
PChar(ReFile),
pchar(LoFile),
false,
File_Attribute_Normal,
Ftp_Transfer_Type_Binary,
0);
if not bGetFile then
begin
memo1.Lines.Add(ReFile+'下载失败!');
inc(ErrNum);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Result:=False;
Exit;
end; memo1.lines.add(ReFile+'下载成功!');
sleep(20);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ErrNum:=0;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin memo1.Lines.Add('操作失败!请检查!');
//control := false;
//time := 0;
exit;end;