Модератор: Модераторы
procedure TMainForm.Synchronization(ftp: TFtpSend; ServerPath, LocalPath: AnsiString);
var
i: integer;
aName: AnsiString;
begin
ftp.ChangeWorkingDir(ServerPath);
ftp.List('', false);
for i:=0 to ftp.FtpList.Count - 1 do
begin
Application.ProcessMessages;
aName := ftp.FtpList.Items[i].FileName;
if not ftp.FtpList.Items[i].Directory then
begin
if (not FileExistsUTF8(AppendPathDelim(LocalPath) + aName)) then
// файл не найден в локальной папке
begin
ftp.DirectFile := true;
ftp.DirectFileName := AppendPathDelim(LocalPath) + aName;
if ftp.RetrieveFile(UTF8ToSys(aName), false) then ShowMessage('Файл ' + aName + ' успешно закачан.')
else ShowMessage('Ошибка при загрузке файла. Код ошибки ' + ftp.ResultString);
FileSetDateUTF8(ftp.DirectFileName, DateTimeToFileDate(ftp.FtpList.Items[i].FileTime));
end else
begin
if (FileAgeUTF8(AppendPathDelim(LocalPath) + aName) <> DateTimeToFileDate(ftp.FtpList.Items[i].FileTime)) then
begin
ShowMessage('Обновление существующего файла ' + aName);
ftp.DirectFile := true;
ftp.DirectFileName := AppendPathDelim(LocalPath) + aName;
ftp.RetrieveFile(UTF8ToSys(aName), false);
FileSetDateUTF8(ftp.DirectFileName, DateTimeToFileDate(ftp.FtpList.Items[i].FileTime));
end else
if (FileSize(UTF8ToSys(AppendPathDelim(LocalPath) + aName)) <> ftp.FtpList.Items[i].FileSize) then
begin
ftp.DirectFile := true;
ftp.DirectFileName := AppendPathDelim(LocalPath) + aName;
if ftp.RetrieveFile(UTF8ToSys(aName), false) then ShowMessage('Файл ' + aName + ' успешно закачан.')
else ShowMessage('Ошибка при загрузке файла. Код ошибки ' + ftp.ResultString);
FileSetDateUTF8(ftp.DirectFileName, DateTimeToFileDate(ftp.FtpList.Items[i].FileTime));
end;
end;
end;
end;
ftp.ChangeToRootDir;
end;
procedure TMainForm.AutoUpdate;
var
ftpclient: TFtpSend;
begin
try
ftpclient := TFtpSend.Create;
ftpclient.FtpList.Clear;
ftpclient.BinaryMode := False;
ftpclient.TargetHost := 'host';
ftpclient.UserName := 'login';
ftpclient.Password := 'pwd';
ftpclient.TargetPort := cFtpProtocol;
ftpclient.PassiveMode := true;
if ftpclient.Login then
begin
Synchronization(ftpclient, 'ftp://192.168.0.1/pub/', 'c:\temp\');
ftpclient.Logout;
end else ShowMessage('Авторизация прошла не успешно: ' + ftpclient.ResultString);
finally
FreeAndNil(ftpclient);
end;
end;
ftp.DirectFile := true;
ftp.DirectFileName := AppendPathDelim(LocalPath) + aName;
ftp.RetrieveFile(UTF8ToSys(aName), false);
if pFTPClient.RetrieveFile(lcFilePathFtp, false) then
pFTPClient.DataStream.SaveToFile(lcFilePathPc);//сохранили из потока на диск
Сейчас этот форум просматривают: Yandex [Bot] и гости: 224