請問使用indy 的IdFTP要如何上傳或下載一個目錄 |
缺席
|
anglo
一般會員 發表:11 回覆:7 積分:3 註冊:2003-06-23 發送簡訊給我 |
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
|
anglo
一般會員 發表:11 回覆:7 積分:3 註冊:2003-06-23 發送簡訊給我 |
RaynorPao大大您好~我在http://delphi.ktop.com.tw/topic.php?topic_id=24349 ,看到N/A大大分享了如何從ftp下載*.*的方法,如下 Question/Problem/Abstract: How can I download all files using *.* or other wildcard characters from within Delphi? Answer: You will have to try this out, as I'm at work and can't really do it, but, heh, again, I'm at work. So, I got bored, and wrote this up real quick. If you all find any problems, or have any solutions, please don't hesitate to post.... Anyyyways, without further procrastination, here ya go: Uses WININEt; function TMyFtp.FindFiles: TStringList;
var
FindData: TWin32FindData;
FindHandle: HInternet;
Begin
FindHandle := FtpFindFirstFile(FFtphandle, '*.*',
FindData, 0, 0);
If FindHandle = nil Then
Begin
Result := nil;
Exit;
End;
FCurFiles.Clear;
FCurFiles.Add(GetFindDataStr(FindData)); While InternetFindnextFile(FindHandle, @FindData) Do
FCurFiles.Add(GetFindDataStr(FindData));
InternetCloseHandle(Findhandle);
GetCurrentDirectory;
Result := FCurFiles;
End; function GetFindDataStr(FindData: TWin32FindData): string; //Get current files in directory var
S: string;
Temp: string;
Begin
S := S GetDots(75);
Move(FindData.CFilename[0], S[6], StrLen(FindData.CFileName));
Temp := IntToStr(FindData.nFileSizeLow);
Move(Temp[1], S[25], Length(Temp));
Result := S;
End; function TMyFtp.FindFiles: TStringList;
var
FindData: TWin32FindData;
FindHandle: HInternet;
Begin
FindHandle := FtpFindFirstFile(FFtphandle, '*.pjl',
FindData, 0, 0); If FindHandle = nil then
Begin
Result := nil;
Exit;
end; FCurFiles.Clear;
FCurFiles.Add(GetFindDataStr(FindData)); While InternetFindnextFile(FindHandle, @FindData) Do FCurFiles.Add(GetFindDataStr(FindData));
InternetCloseHandle(Findhandle);
GetCurrentDirectory;
Result := FCurFiles; End; function TECU.GetFile(FTPFile, NewFile: string): Boolean; //Download a File Through FTP begin
Result := FtpGetFile(FFTPHandle, PChar(FTPFile), PChar(NewFile), False, File_Attribute_Normal, Ftp_Transfer_Type_Binary, 0);
end; Procedure Button1.Onclick();
ar
MyHandle: HINTERNET; //handle from InternetConnect
Begin
MyHandle := InternetOpen(`ECU', 0, nil, 0, 0);
InternetConnect(MyHandle, ftp://ftp.mysite.com, 0, Anonymouse, user@mysite.com, INTERNET_SERVICE_FTP, INTERNET_CONNECT_FLAG_PASSIVE, 0 ); //Changes to a specific directory once connected
TECU.ChangeDirExact('ftp://ftp.mysite.com/downloads');
FindHandle := FtpFindFirstFile(FFtphandle, '*35L.PJL', FindData, 0, 0); // If the directory is blank, then tell me about it. Else, download all.
If FindHandle = nil Then
Begin
Result := nil;
ShowMessage('The file was not able to be downloaded. Please Re-Try');
End Else
TECU.GetFile('*.*', 'c:\*.*');
End;
End; //The call InternetConnect Uses the following function ( included with WinInet ): {*******************************************************************************
function InternetConnect(
hInet: HINTERNET; // Handle from InternetOpen
lpszServerName: PChar; // Server: i.e., www.borland.com
nServerPort: INTERNET_PORT; // Usually 0
lpszUsername: PChar; // usually anonymous
lpszPassword: PChar; // usually your email address
dwService: DWORD; // FTP, HTTP, or Gopher?
dwFlags: DWORD; // Usually 0
dwContext: DWORD): // User defined number for callback
HINTERNET; stdcall; *******************************************************************************} // Again, this is not 100% concrete to work, so, make it concrete by posting ;)
// Thanks
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |