如何編寫一個建立FTP網站的函數?
Function ASTCreateFtpSite(IPAddress, RootDirectory, ServerComment, HostName, PortNum, Computer, Start,LogFileDirectory)
Dim MSFTPSVC, FtpServer, NewFtpServer, NewDir
Dim Bindings, BindingString, NewBindings, Index, SiteObj, bDone
On Error Resume Next
Err.Clear
Set MSFTPSVC = GetObject("IIS://" & Computer & "/MSFTPSVC")
If Err.Number <> 0 Then
WScript.Echo "無法開啟: "&"IIS://" & Computer & "/MSFTPSVC" & VbCrlf & "程式將退出!"
WScript.Quit (1)
End If
BindingString = IpAddress & ":" & PortNum & ":" & HostName
For Each FtpServer in MSFTPSVC
If FtpServer.Class="IIsFtpServer" Then
Bindings = FtpServer.ServerBindings
If BindingString = Bindings(0) Then
WScript.Echo "噢,IP地址衝突:" & IpAddress & ",請檢測IP地址!" & VbCrlf & "取消建立本網站."
Exit Function
End If
End If
Next
Index = 1
bDone = False
While (Not bDone)
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/MSFTPSVC/" & Index)
If (Err.Number = 0) Then
Index = Index + 1
Else
Err.Clear
Set NewFtpServer = MSFTPSVC.Create("IIsFtpServer", Index)
If (Err.Number <> 0) Then
Index = Index + 1
Else
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/MSFTPSVC/" & Index)
If (Err.Number = 0) Then
bDone = True
Else
Index = Index + 1
End If
End If
End If
If (Index > 10000) Then
WScript.Echo "噢,建立網站異常!正在建立的網站的序號為:"&Index&"." & VbCrlf & "取消建立本網站."
Exit Function
End If
Wend
NewBindings = Array(0)
NewBindings(0) = BindingString
NewFtpServer.ServerBindings = NewBindings
NewFtpServer.ServerComment = ServerComment
NewFtpServer.AllowAnonymous = False
NewFtpServer.AccessWrite = True
NewFtpServer.AccessRead = True
NewFtpServer.DontLog = False
NewFtpServer.LogFileDirectory = LogFileDirectory
NewFtpServer.SetInfo
Set NewDir = NewFtpServer.Create("IIsFtpVirtualDir", "ROOT")
NewDir.Path = RootDirectory
NewDir.AccessRead = true
Err.Clear
NewDir.SetInfo
If (Err.Number = 0) Then
Else
WScript.Echo "噢,主目錄建立時出錯!"
End If
If Start = True Then
Err.Clear
Set NewFtpServer = GetObject("IIS://" & Computer & "/MSFTPSVC/" & Index)
NewFtpServer.Start
If Err.Number <> 0 Then
WScript.Echo "噢,啟動網站時出錯!"
Err.Clear
Else
End If
End If
ASTCreateFtpSite = Index
End Function