Download a directory 2 using FTP controls 2

zhaozj2021-02-08  248

Download a directory 2 using FTP controls 2

The last written article "Download a directory using the FTP control", the directory downloaded in the directory is normal in NT, but the upgrade to 2000 cannot be used normally. Change the directory list style in the FTP site properties of Windows 2000 to Unix. I think it is too old NMFTP control from Delphi, and is not good for 2000. I want to download a new version on the website of the company that provides the control, I found to pay $ 199.95 fees! No way, simply do not use the control, directly using the relevant FTP function provided by Microsoft. Use the principles of the inrest and out of the stack, there is a directory and file to put the stack, after downloading, wait until the stack is empty, the entire directory (including the levels of the catalog) is downloaded. The function downloaded throughout the directory is as follows, and it is interested in referring to:

function Tmyftp.dir_download (remotedir: string; localdir: string): Boolean; var dirstack: TStack; prtdir, nowprtdir: PDirstru; dirover: Boolean; begin result: = false; dirstack: = TStack.create; new (prtdir); if prtdir <> Nil then begin prtdir.ftpdirstr: = remotedir; prtdir.localdirstr: = localdir; prtdir.finishflag: = false; dirstack.Push (prtdir); if not directoryexists (localdir) then createdir (localdir); end;

while dirstack.count> 0 do begin nowprtdir: = dirstack.pop; change_dir (nowprtdir ^ .ftpdirstr); ListHandle: = FtpFindFirstFile (FtpHandle, '. * *', FindData, 0,0); if ListHandle <> Nil then begin dirover: = true; while dirover do begin if finddata.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then begin new (prtdir); if prtdir <> Nil then begin prtdir.ftpdirstr: = nowprtdir ^ .ftpdirstr finddata.cfilename '/'; prtdir.localdirstr: = nowprtdir ^ .localdirstr finddata.cfilename '/'; prtdir.finishflag: = false; dirstack.Push (prtdir); if not directoryexists (nowprtdir ^ .localdirstr trim (finddata.cfilename)) then createdir (nowprtdir ^ .localdirstr Trim (Finddata.cfileName); END Else Begin errno: = 4; errmsg: = 'Cannot request memory during the directory DOWNLOAD.

'; Raise FtpException.create (errmsg); end end else begin try if not FtpGetFile (FtpHandle, pchar (nowprtdir ^ .ftpdirstr finddata.cfilename), pchar (nowprtdir ^ .localdirstr finddata.cfilename), false, 0,0 0) The begin errno: = 5; errmsg: = 'In the Download file' nowPRTDIR ^ .ftpdirstr findData.cfileName 'error. '; Raise ftpexception.create (Errmsg); End; Except on Exception Do Begin errno: = 6; errmsg: =' An exception error occurs when Download file ' nowPRTDIR ^ .ftpdirstr Findata.cfileName '. '; Raise FtpException.create (errmsg); end; end end; dirover: = InternetFindNextFile (ListHandle, @ finddata) end; InternetCloseHandle (ListHandle); end else begin end; dispose (nowprtdir); end; end;

http://www.softcows.com/cn

转载请注明原文地址:https://www.9cbs.com/read-3393.html

New Post(0)