如何编写一个创建FTP站点的函数?
FunctionASTCreateFtpSite(IPAddress,RootDirectory,ServerComment,HostName,PortNum,Computer,Start,LogFileDirectory)
DimMSFTPSVC,FtpServer,NewFtpServer,NewDir
DimBindings,BindingString,NewBindings,Index,SiteObj,bDone
OnErrorResumeNext
Err.Clear
SetMSFTPSVC=GetObject("IIS://"&Computer&"/MSFTPSVC")
IfErr.Number<>0Then
WScript.Echo"无法打开:"&"IIS://"&Computer&"/MSFTPSVC"&VbCrlf&"程序将退出!"
WScript.Quit(1)
EndIf
BindingString=IpAddress&":"&PortNum&":"&HostName
ForEachFtpServerinMSFTPSVC
IfFtpServer.Class="IIsFtpServer"Then
Bindings=FtpServer.ServerBindings
IfBindingString=Bindings(0)Then
WScript.Echo"噢,IP地址冲突:"&IpAddress&",请检测IP地址!"&VbCrlf&"取消创建本站点."
ExitFunction
EndIf
EndIf
Next
Index=1
bDone=False
While(NotbDone)
Err.Clear
SetSiteObj=GetObject("IIS://"&Computer&"/MSFTPSVC/"&Index)
If(Err.Number=0)Then
Index=Index+1
Else
Err.Clear
SetNewFtpServer=MSFTPSVC.Create("IIsFtpServer",Index)
If(Err.Number<>0)Then
Index=Index+1
Else
Err.Clear
SetSiteObj=GetObject("IIS://"&Computer&"/MSFTPSVC/"&Index)
If(Err.Number=0)Then
bDone=True
Else
Index=Index+1
EndIf
EndIf
EndIf
If(Index>10000)Then
WScript.Echo"噢,创建站点异常!正在创建的站点的序号为:"&Index&"."&VbCrlf&"取消创建本站点."
ExitFunction
EndIf
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
SetNewDir=NewFtpServer.Create("IIsFtpVirtualDir","ROOT")
NewDir.Path=RootDirectory
NewDir.AccessRead=true
Err.Clear
NewDir.SetInfo
If(Err.Number=0)Then
Else
WScript.Echo"噢,主目录创建时出错!"
EndIf
IfStart=TrueThen
Err.Clear
SetNewFtpServer=GetObject("IIS://"&Computer&"/MSFTPSVC/"&Index)
NewFtpServer.Start
IfErr.Number<>0Then
WScript.Echo"噢,启动站点时出错!"
Err.Clear
Else
EndIf
EndIf
ASTCreateFtpSite=Index
EndFunction