Ранг: 748.2 (! !), 390thx Активность: 0.37↘0 Статус: Участник bytecode!
|
Создано: 27 июля 2006 16:23 · Личное сообщение · #2
function TMain.FtpSaveFile(strHost, strUser, strPwd: string;
Port: Integer; localDir: string): Boolean;
var
hNet,hFTP,hFile,hResult : HINTERNET;
sSourceDir : string;
bSuccess : Boolean;
SR : TSearchRec;
iProgress,iDirNum : Integer;
sRec : TWin32FindData;
begin
Result := False;
iProgress := 0;
iDirNum := 0;
SetProgressBarCaption(sPrepare,TRUE);
sFTPPath := StringReplace(sFTPPath,'\','/',[rfReplaceAll]);
sSourceDir := IncludeTrailingPathDelimiter(localDir);
{ Open an internet session }
hNet := InternetOpen('WS Gallery', // Agent
INTERNET_OPEN_TYPE_PRECONFIG, // AccessType
nil, // ProxyName
nil, // ProxyBypass
0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE
{
Agent contains the name of the application or
entity calling the Internet functions
}
{ See if connection handle is valid }
if hNet = nil then
begin
ShowMessage(sWinInetErr);
Exit;
end;
SetProgressBarCaption(sServerConn,TRUE);
{ Connect to the FTP Server }
hFTP := InternetConnect(hNet, // Handle from InternetOpen
PChar(strHost), // FTP server
port, // (INTERNET_DEFAULT_FTP_PORT),
PChar(StrUser), // username
PChar(strPwd), // password
INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?
0, // flag: 0 or INTERNET_FLAG_PASSIVE
0);// User defined number for callback
if hFTP = nil then
begin
InternetCloseHandle(hNet);
ShowMessage(Format(sHostErr,[strHost]));
Exit;
end;
SetProgressBarCaption(sSettingFld + sFTPPath + '...',TRUE);
{ Change directory }
FtpCreateDirectory(hFTP,PChar(sFTPPath));
bSuccess := FtpSetCurrentDirectory(hFTP, PChar(sFTPPath));
if not bSuccess then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
ShowMessage(Format(sFldErr,[sFTPPath]));
Exit;
end;
hResult := FtpFindFirstFile(hFTP,'*.*',sRec,0,0);
if hResult <> nil then
repeat
if (sRec.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY) then
Inc(iDirNum);
until not InternetFindNextFile(hResult,@sRec)
else
iDirNum := 2;
FTPProgress.MaxValue := iFilesCount;
SetProgressBarVal(0);
FtpCreateDirectory(hFTP,PChar(IntToStr(iDirNum)));
FtpSetCurrentDirectory(hFTP,PChar(IntToStr(iDirNum)));
if FindFirst(sSourceDir + '*.*', faAnyFile, SR) = 0 then
begin
repeat
Application.ProcessMessages;
if (SR.Attr <> faDirectory) then
begin
FtpPutFile(hFTP,
PChar(sSourceDir + SR.Name),
PChar(SR.Name),
FTP_TRANSFER_TYPE_BINARY,
0);
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
InternetCloseHandle(hFile);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Result := True;
end;
----- Флэш, ява, дотнет - на завтрак, обед и ужин. Unity3D на закуску. | Сообщение посчитали полезным: |