delphi中的nmftp控件中Download函数只能下载一个文件,没有提供一个下载整个目录(包含子目录)的函数。 file://目录下载function tftp.ex_download(remote_dir,local_dir:string):boolean;vari,j,count1:integer;att,ss:string;current_dir:string;temp_dir:string;begintry beginNMFTP1.ChangeDir(remote_dir);current_dir:=remote_dir;temp_dir:=copy(current_dir,2,length(current_dir));if not DirectoryExists(local_dir) then CreateDir(local_dir);if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);nmftp1.ParseList:=true;NMftp1.list;count1:=nmftp1.FTPDirectoryList.name.Count;for i:=0 to count1-1 do beginfile://必须NMFTP1.ChangeDir(current_dir);nmftp1.list;ss:=nmftp1.FTPDirectoryList.name.Strings[i];att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then beginif not DirectoryExists(local_dir) then CreateDir(local_dir);NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);endelse beginif not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);file://递归调用ex_download(remote_dir+ss+',local_dir);end;end;result:=true;endexceptOn E:Exception do beginresult:=false;end;end;end;
my e-mail:[email protected]
有例子!
http://www.goomoo.net/tmp/FTP.rar
uses
URLMon, ShellApi;function DownloadFile(SourceFile, DestFile: string): Boolean;begintryResult := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;exceptResult := False;end;end;procedure TForm1.Button1Click(Sender: TObject);const// URL LocationSourceFile = 'http://www.google.com/intl/de/images/home_title.gif';// Where to save the fileDestFile = 'c:image.gif';beginif DownloadFile(SourceFile, DestFile) thenbeginShowMessage('Download succesful!');// Show downloaded image in your browserShellExecute(Application.Handle, PChar('open'), PChar(DestFile),PChar(''), nil, SW_NORMAL)endelseShowMessage('Error while downloading ' + SourceFile)end;// Minimum availability: Internet Explorer 3.0// Minimum operating systems Windows NT 4.0, Windows 95******************************2.}usesWininet;function DownloadURL(const aUrl: string): Boolean;varhSession: HINTERNET;hService: HINTERNET;lpBuffer: array[0..1024 + 1] of Char;dwBytesRead: DWORD;beginResult := False;// hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);tryif Assigned(hSession) thenbeginhService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);if Assigned(hService) thentrywhile True dobegindwBytesRead := 1024;InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);if dwBytesRead = 0 then break;lpBuffer[dwBytesRead] := #0;Form1.Memo1.Lines.Add(lpBuffer);end;Result := True;finallyInternetCloseHandle(hService);end;end;finallyInternetCloseHandle(hSession);end;end;******************************在Delphi中如何从网络中提取一个文件到本地计算机中,如提取<BR> http://www.abcdefg.com/software/a.zip到本地指定的目录中?在窗体中添加1个TNMHTTP控件(在FastNet页)然后在随便那个Button什么的下面加入如下代码: NMHTTP1.InputFileMode := ture;NMHTTP1.Body := '本地文件名';NMHTTP1.Header := 'Head.txt';NMHTTP1.OutputFileMode := FALSE;NMHTTP1.ReportLevel := Status_Basic;NMHTTP1.Proxy := '代理服务器的IP地址';NMHTTP1.ProxyPort := '代理服务器的端口号';With NMHTTP1.HeaderInfo doBeginCookie := '';LocalMailAddress := '';LocalProgram := '';Referer := '';UserID := '用户名称';Password := '用户口令';End;NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);试试吧,Delphi的目录中有TNMHTTP控件的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。uses URLMon;...OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));其中最后一个参数你还可以传入一个IBindStatusCallback的实现以跟踪下载进度或控制中止下载。简单的场合一句话就搞定了。
你好很感谢你,现在我delphi是原装版没有装过任何新的控件,你那个例程有很多控件我都没有
希望你把那些控件给我down可以吗?非常感谢^_^我会给分的放心
心痛咯!55555555555555555
file://目录下载function tftp.ex_download(remote_dir,local_dir:string):boolean;vari,j,count1:integer;att,ss:string;current_dir:string;temp_dir:string;begintry beginNMFTP1.ChangeDir(remote_dir);current_dir:=remote_dir;temp_dir:=copy(current_dir,2,length(current_dir));if not DirectoryExists(local_dir) then CreateDir(local_dir);if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);nmftp1.ParseList:=true;NMftp1.list;count1:=nmftp1.FTPDirectoryList.name.Count;for i:=0 to count1-1 do beginfile://必须NMFTP1.ChangeDir(current_dir);nmftp1.list;ss:=nmftp1.FTPDirectoryList.name.Strings[i];att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then beginif not DirectoryExists(local_dir) then CreateDir(local_dir);NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);endelse beginif not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);file://递归调用ex_download(remote_dir+ss+',local_dir);end;end;result:=true;endexceptOn E:Exception do beginresult:=false;end;end;end;