源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
查看: 621|回复: 12

[编程10000问] 如何编写一个创建FTP站点的函数?

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2006-11-16 00:00:00 | 显示全部楼层 |阅读模式

如何编写一个创建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

回复

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2022-9-16 05:29:38 | 显示全部楼层
好人好人好人好人
回复 支持 反对

使用道具 举报

15

主题

1万

回帖

122

积分

注册会员

Rank: 2

积分
122
发表于 2023-6-12 09:48:09 | 显示全部楼层
这个源码不错啊
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

66

积分

注册会员

Rank: 2

积分
66
发表于 2024-1-25 02:40:16 | 显示全部楼层
好东西一定要看看!
回复 支持 反对

使用道具 举报

2

主题

1万

回帖

69

积分

注册会员

Rank: 2

积分
69
发表于 2024-6-1 01:36:04 | 显示全部楼层
2222222222222222
回复 支持 反对

使用道具 举报

2

主题

1万

回帖

99

积分

注册会员

Rank: 2

积分
99
发表于 2024-6-3 08:53:40 | 显示全部楼层
呵呵呵呵呵呵
回复 支持 反对

使用道具 举报

6

主题

1万

回帖

174

积分

注册会员

Rank: 2

积分
174
发表于 2024-6-24 16:25:28 | 显示全部楼层
抽根烟,下来看看再说
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-7-22 15:52:42 | 显示全部楼层
。。。。。。。。。。。。。。。
回复 支持 反对

使用道具 举报

1

主题

1万

回帖

79

积分

注册会员

Rank: 2

积分
79
发表于 2024-8-16 16:58:29 | 显示全部楼层
哦哦哦哦哦哦哦哦哦
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

120

积分

注册会员

Rank: 2

积分
120
发表于 2024-9-1 18:34:55 | 显示全部楼层
而非为吾问无为谓娃娃
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2024-9-21 10:44 , Processed in 0.256767 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表