全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3119
推到 Plurk!
推到 Facebook!

從FTP下載全部檔案(*.*)的方法

 
flyup
資深會員


發表:280
回覆:508
積分:385
註冊:2002-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-12-27 13:25:18 IP:61.217.xxx.xxx 未訂閱
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 ---------------- 局局棋盤步步新, 變化無常平常待。 人生相處平常心, 無憂無慮心事成。 ----------------
系統時間:2024-04-20 8:23:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!