助人快乐之本
uses Wininet;
var
hConnect,hSession,hFind:HInternet;
procedure TForm1.Button1Click(Sender: TObject);
begin
if assigned(hConnect) then
InternetCloseHandle(hConnect);
hSession:=InternetOpen('MySoft',Internet_open_type_preconfig,nil,nil,0);
if assigned(hSession) then
begin
hConnect:=InternetConnect(
hSession,
PChar(Edit1.Text),
21,
//Internet_Default_ftp_port,
PChar('anonymous'),
PChar('tingweb@wx88.net'),
Internet_Service_ftp,
Internet_Flag_passive,
0);
{以上为连接FTP部分}
if assigned(hConnect) then
begin
FTPSetCurrentDirectory(hConnect,PChar('database/my'));
Label1.Caption:=GetCurrentDirectory;
ShowMessage('完毕!');
end;
end;
end;
然后
var
lpFindFileData:TWin32FindData;
isDirectory:Boolean;
begin
FTPSetCurrentDirectory(hConnect,PChar(Directory));
//
Label1.Caption:=GetCurrentDirectory;
hFind:=FTPFindFirstFile(hConnect,nil,lpFindFileData,0,0);
if assigned(hFind) then
begin
//if GetLastError<>ERROR_NO_MORE_FILES then
begin
repeat
isDirectory:=(lpFindFileData.dwFileAttributes and File_Attribute_Directory)=FILE_Attribute_Directory;
IF isDirectory then
begin
Memo1.Lines.Add(String(lpFindFileData.cFileName));
//AddFTPFile(lpFindFileData);
SetDirectory(String(lpFindFileData.cFileName));
//递归
end
else
begin
AddFTPFile(lpFindFileData);
end;
until InternetFindNextFile(hFind,@lpFindFileData)=False;
end;
InternetCloseHandle(hFind);
end;
end;