VBA管理filezilla 之用戶組及共享目錄權限批量代碼
表格數據
VBA模塊代碼:
Option Explicit
Dim str, xmlfile As String
Dim i As Integer
Sub xiegroups()
Dim GROUPS
Set GROUPS = Sheets("GROUPS")
‘用戶組信息開始寫入
str = " <Groups>"
Call xiexml(str)
For i = 2 To GROUPS.Range("A65535").End(xlUp).Row
‘判斷如果是用戶組的第一行
If GROUPS.Range("B" & i) = 1 Then
str = " <Group Name=" & Chr(34) & GROUPS.Range("A" & i) & Chr(34) & ">"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "Bypass server userlimit" & Chr(34) & ">0</Option>"
str = " <Option Name=" & Chr(34) & "User Limit" & Chr(34) & ">0</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "IP Limit" & Chr(34) & ">0</Option>"
str = " <Option Name=" & Chr(34) & "Enabled" & Chr(34) & ">1</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "Comments" & Chr(34) & ">" & GROUPS.Range("C" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "ForceSsl" & Chr(34) & ">0</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "8plus3" & Chr(34) & ">0</Option>"
Call xiexml(str)
str = " <IpFilter>"
Call xiexml(str)
str = " <Disallowed />"
Call xiexml(str)
str = " <Allowed />"
Call xiexml(str)
str = " </IpFilter>"
Call xiexml(str)
str = " <Permissions>"
Call xiexml(str)
End If
‘目錄及權限設置
str = " <Permission Dir=" & Chr(34) & GROUPS.Range("D" & i) & Chr(34) & ">"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "FileRead" & Chr(34) & ">" & GROUPS.Range("E" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "FileWrite" & Chr(34) & ">" & GROUPS.Range("F" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "FileDelete" & Chr(34) & ">" & GROUPS.Range("G" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "FileAppend" & Chr(34) & ">" & GROUPS.Range("H" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "DirCreate" & Chr(34) & ">" & GROUPS.Range("I" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "DirDelete" & Chr(34) & ">" & GROUPS.Range("J" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "DirList" & Chr(34) & ">" & GROUPS.Range("K" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "DirSubdirs" & Chr(34) & ">" & GROUPS.Range("L" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "IsHome" & Chr(34) & ">" & GROUPS.Range("M" & i) & "</Option>"
Call xiexml(str)
str = " <Option Name=" & Chr(34) & "AutoCreate" & Chr(34) & ">" & GROUPS.Range("N" & i) & "</Option>"
Call xiexml(str)
str = " </Permission>"
Call xiexml(str)
‘判斷是否用戶組的最後一行
If GROUPS.Range("B" & i) = Application.WorksheetFunction.CountIf(GROUPS.Range("A:A"), GROUPS.Range("A" & i)) Then
str = " </Permissions>"
Call xiexml(str)
str = " <SpeedLimits DlType=" & Chr(34) & "1" & Chr(34) & " DlLimit=" & Chr(34) & "10" & Chr(34) & " ServerDlLimitBypass=" & Chr(34) & "0" & Chr(34) & " UlType=" & Chr(34) & "1" & Chr(34) & " UlLimit=" & Chr(34) & "10" & Chr(34) & " ServerUlLimitBypass=" & Chr(34) & "0" & Chr(34) & ">"
Call xiexml(str)
str = " <Download />"
Call xiexml(str)
str = " <Upload />"
Call xiexml(str)
str = " </SpeedLimits>"
Call xiexml(str)
str = " </Group>"
Call xiexml(str)
End If
Next
‘用戶組信息寫入結束
str = " </Groups>"
Call xiexml(str)
End Sub
Sub xiexml(AnyString)
xmlfile = "G:\11\filezilla.xml"
Open xmlfile For Append As #1
Print #1, str
Close #1
End Sub
輸出效果
VBA管理filezilla 之用戶組及共享目錄權限批量代碼