如何编写一个创建FTP站点的函数?
如何编写一个创建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
上一篇: 如何提高Request集合的使用效率?
下一篇: 【ASP.NET Core学习】基础