1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| //------------------------------------------------------------------------------
procedure TxxxSpareFTPServer.ListDirectoryEventHandler(ASender: TIdFTPServerContext; const APath: TIdFTPFileName; ADirectoryListing: TIdFTPListOutput; const ACmd, ASwitches: string);
procedure AddItemToListOutput(const AItemName: TFileName; AItemType: TIdDirItemType; AItemSize: Int64; AItemDate: TDateTime);
begin
with ADirectoryListing.Add() do
begin
ItemType := AItemType;
FileName := AItemName;
Size := AItemSize;
ModifiedDate := AItemDate;
// Simule les même droits que sur "ftp.xxxxxxxxxxx.com" pour l'utilisateur "xxx" !
OwnerName := ASender.Username;
GroupName := 'all';
if ItemType = ditDirectory then
begin
UnixOwnerPermissions := 'rwx';
UnixGroupPermissions := 'r-x';
UnixOtherPermissions := 'r-x';
end
else
begin
UnixOwnerPermissions := 'rw-';
UnixGroupPermissions := 'r--';
UnixOtherPermissions := 'r--';
end;
end;
end;
procedure EnumFiles(const ALocalDir: TFileName; const AFilter: TFileName);
var
sr: TSearchRec;
begin
if System.SysUtils.FindFirst(IncludeTrailingPathDelimiter(ALocalDir) + AFilter, faNormal, sr) = 0 then
begin
try
repeat
AddItemToListOutput(sr.Name, ditFile, sr.Size, sr.TimeStamp);
until FindNext(sr) <> 0;
finally
System.SysUtils.FindClose(sr);
end;
end;
end;
procedure EnumDirectories(const ALocalDir: TFileName);
var
Filter: string;
sr: TSearchRec;
begin
Filter := IncludeTrailingPathDelimiter(ALocalDir) + '*';
if System.SysUtils.FindFirst(Filter, faDirectory, sr) = 0 then
begin
try
repeat
if ((sr.Attr and faDirectory) = faDirectory) and (sr.Name <> '.') and (sr.Name <> '..') then
begin
AddItemToListOutput(sr.Name, ditDirectory, sr.Size, sr.TimeStamp);
end;
until System.SysUtils.FindNext(sr) <> 0;
finally
System.SysUtils.FindClose(sr);
end;
end;
end;
var
WinCurrentDir, WinNewDir, WinNewCompleteDir: TFileName;
ld: Integer;
Filter: TFileName;
begin
try
WinCurrentDir := ChangeToWindowsPathDelimiter(ASender.CurrentDir);
if ContainsStr(APath, '*') then
begin
if APath[Length(APath)] = PATH_DELIMITER_FTP then
WinNewDir := Copy(APath, 1, Length(APath) - 1)
else
WinNewDir := APath;
ld := LastDelimiter(PATH_DELIMITER_FTP, WinNewDir);
Filter := Copy(WinNewDir, ld + 1, MaxInt);
WinNewDir := ChangeToWindowsPathDelimiter(Copy(WinNewDir, 1, ld));
end
else
WinNewDir := ChangeToWindowsPathDelimiter(APath);
WinNewCompleteDir := ExpandWindowsPath(FLocalRootDirectory, WinCurrentDir, WinNewDir);
if DirectoryExists(WinNewCompleteDir) then
begin
if Filter = '' then
begin
// Les Fichiers !
// Toutes les extensions pour les voir via FileZilla même ce n'est ni des .dat et ni des .tmp
EnumFiles(WinNewCompleteDir, '*.*');
// Les Dossiers !
EnumDirectories(WinNewCompleteDir);
end
else
EnumFiles(WinNewCompleteDir, Filter);
end
else
raise ExxxSpareFTPServerException.CreateFmt('%s: Failed to retrieve the contents of the folder', [APath]);
except
on E: Exception do
begin
DoError(APath, E.Message);
raise;
end;
end;
end; |
Partager