·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> IIS7:通过脚本来配置ftp站点

IIS7:通过脚本来配置ftp站点

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

IIS7:通过脚本来配置ftp站点

Appcmd.exe是IIS7提供的一个管理站点的命令行工具,同时支持Ftp和Http的站点,功能还算强大,具体使用方法参考微软网站。

需求

我这里的例子主要配置一个Ftp站点,并且允许CcUser这个用户对其目录具备读和写的权限:

image

代码

@echo offset cc_inbox_dir=c:\CC_Inboxset cc_outbox_dir=c:\CC_Outboxset appcmd_exe=%systemroot%\system32\inetsrv\appcmd.exeset ftp_siet_name=CC_Inbox::create cc inbox folder::rd /S /Q %cc_inbox_dir%IF NOT EXIST %cc_inbox_dir% (md %cc_inbox_dir%)::create cc outbox folder::rd /S /Q %cc_outbox_dir%IF NOT EXIST %cc_outbox_dir% (md %cc_outbox_dir%)::delete the ftp site and then make a new one. ID of the ftp site will be auto-generated.%appcmd_exe% delete site %ftp_siet_name%%appcmd_exe% add site /name:%ftp_siet_name% /bindings:ftp://*:21 /physicalpath:%cc_inbox_dir%::add virtual dir for cc outbox. Note there is "/' at the end of the app.name%appcmd_exe% add vdir /app.name:"%ftp_siet_name%/" /path:/outbox /physicalpath:%cc_outbox_dir%::config ftp authentication%appcmd_exe% set site %ftp_siet_name% -ftpServer.security.ssl.controlChannelPolicy:SslAllow -ftpServer.security.ssl.dataChannelPolicy:SslAllow -ftpServer.security.authentication.basicAuthentication.enabled:true::config ftp authorization to allow CcUser to read and write%appcmd_exe% set config %ftp_siet_name% -section:system.ftpServer/security/authorization /+"[accessType='Allow',users='CcUser',permissions='Read, Write']" /commit:apphost

要点

  • appcmd.exe默认没有添加到Path里,需要指定完整的路径。
  • 如果64机器上应该使用64位的版本,32位的版本在Wow64目录下
  • 如果需要ip Address设置成“All Unassigned”,在bindings的时候使用“*”,而不要使用ip地址或机器名
  • “/app.name”参数的值应该以“/”结尾,比如应该用“CC_Inbox/”而不是“CC_Inbox”
  • Authentication的设置在添加ftp站点的时候没法设置,但是可以通过修改ftp站点的属性来完成
  • Authorization(比如文件的访问权限)不在ftp站点的属性中,而是system级别的属性,修改完最后记得提交 “/commit:apphost”

参考资料

  • IIS官方文档:Getting Started with AppCmd.exe
  • IIS官方文档:http://www.iis.net/configreference/system.ftpserver/security/authorization
  • 通过修改配置文件(applicationHost.config)的方式创建ftp站点