通过脚本将网站和 FTP 添加到 IIS 7 中

发布于 2024-12-07 18:07:04 字数 1059 浏览 0 评论 0原文

我们正在将 100 多个域转移到新服务器。我创建了一个脚本,允许使用简单的 BAT 文件将网站条目和 FTP 条目添加到 IIS 7 中。我发现了几个使用 AppCmd ADD SITE 的教程,效果非常好。通过运行 :: c:\scripts\createIIS.bat youdomainname.com 。有反馈吗? - 它正在工作。

@Echo off
:: --------------------------------------------
:: Create IIS 7 Site Entry / FTP Site
:: --------------------------------------------

:: Get variable from command %1 Root Domain Name.
set rootDomainName = %1

:: This is the path to the Web Pages on the server.
set WebFile=C:\websites\

:: ADD NEW Directory
MKDIR %WebFile%%1

:: ADD IIS ENTRY
%windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/*:80:%1,http/*:80:www.%1 /physicalPath:C:\websites\%1

:: --------------------------------------------
:: CREATE FTP in IIS
:: --------------------------------------------
%windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1"


echo New Directory Created:  %WebFile%%1
echo IIS Website Created:  %1  and  www.%1
echo FTP SITE Created:  %1
echo ...
echo ...
echo COMPLETED!
pause

We are in the process of moving over 100 domains over to a new server. I have created a script that will allow adding a Website entry and FTP entry into IIS 7 using a simple BAT file. I found several tutorials using AppCmd ADD SITE which works very well. By running :: c:\scripts\createIIS.bat youdomainname.com . Any feed-back? - It is working.

@Echo off
:: --------------------------------------------
:: Create IIS 7 Site Entry / FTP Site
:: --------------------------------------------

:: Get variable from command %1 Root Domain Name.
set rootDomainName = %1

:: This is the path to the Web Pages on the server.
set WebFile=C:\websites\

:: ADD NEW Directory
MKDIR %WebFile%%1

:: ADD IIS ENTRY
%windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/*:80:%1,http/*:80:www.%1 /physicalPath:C:\websites\%1

:: --------------------------------------------
:: CREATE FTP in IIS
:: --------------------------------------------
%windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1"


echo New Directory Created:  %WebFile%%1
echo IIS Website Created:  %1  and  www.%1
echo FTP SITE Created:  %1
echo ...
echo ...
echo COMPLETED!
pause

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猛虎独行 2024-12-14 18:07:04

很棒的剧本。尽管这不是一个真正的问题,但我对它进行了一些修改以进行批处理。

首先,我创建了一个批处理文件,该文件读取要添加的网站的文本文件,该文件引用稍作修改的批处理文件以仅创建网站(不需要 FTP):

@Echo off
:: ---------------------------------------------------------------------------------------
:: Create Batched IIS 7 Site Entries
:: 
::   Usage: CreateIISEntry.bat [websitename.com] (no www.)
:: 

for /f %%X in (NewWebsiteEntries.txt) do CreateSingleIISEntry.bat %%X


echo ...
echo *** BATCH PROCESS HAS BEEN COMPLETED ***

NewWebsiteEntries.txt 包含要创建的网站列表 - 每行一个(不包括 www.):

site1.com
site2.com
site3.com

最后,创建条目的批处理文件:

@Echo off
:: ---------------------------------------------------------------------------------------
:: Create IIS 7 Site Entry
:: 
::   Usage: CreateSingleIISEntry.bat [websitename.com] (no www.)
:: ---------------------------------------------------------------------------------------

:: Get variable from command %1 Root Domain Name.
set rootDomainName = %1

:: This is the path to the Web Pages on the server.
set WebFile=C:\inetpub\wwwroot\

:: ADD NEW Directory
MKDIR %WebFile%%1
echo New Directory Created:  %WebFile%%1

xcopy C:\inetpub\wwwroot\NewWebsiteHolding\*.* %WebFile%%1

:: ADD IIS ENTRY
%windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/[YOUR IP ADDRESS OR *]:80:%1,http/[YOUR IP ADDRESS OR *]:80:www.%1 /physicalPath:%WebFile%%1
echo IIS Website Created:  %1  and  www.%1

#:: --------------------------------------------
#:: CREATE FTP in IIS
#:: --------------------------------------------
#%windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1"
#
#


#echo FTP SITE Created:  %1
echo ...
echo ...
echo New website added ========================= %1

由于在我的情况下,并非所有新站点都会立即生效,因此我将其内容复制到新创建的网站目录中的默认占位符站点。

这会将所有网站添加到默认应用程序池。

就是这样。

Great script. Even though this isn't really a question, I modified it somewhat for batch processing.

First, I created a batch file that reads in a text file of websites to add, that references your slightly modified batch file to only create websites (no FTP's required):

@Echo off
:: ---------------------------------------------------------------------------------------
:: Create Batched IIS 7 Site Entries
:: 
::   Usage: CreateIISEntry.bat [websitename.com] (no www.)
:: 

for /f %%X in (NewWebsiteEntries.txt) do CreateSingleIISEntry.bat %%X


echo ...
echo *** BATCH PROCESS HAS BEEN COMPLETED ***

NewWebsiteEntries.txt contains a list of websites to create - one per line (no www. included):

site1.com
site2.com
site3.com

Lastly, the batch file that creates the entries:

@Echo off
:: ---------------------------------------------------------------------------------------
:: Create IIS 7 Site Entry
:: 
::   Usage: CreateSingleIISEntry.bat [websitename.com] (no www.)
:: ---------------------------------------------------------------------------------------

:: Get variable from command %1 Root Domain Name.
set rootDomainName = %1

:: This is the path to the Web Pages on the server.
set WebFile=C:\inetpub\wwwroot\

:: ADD NEW Directory
MKDIR %WebFile%%1
echo New Directory Created:  %WebFile%%1

xcopy C:\inetpub\wwwroot\NewWebsiteHolding\*.* %WebFile%%1

:: ADD IIS ENTRY
%windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/[YOUR IP ADDRESS OR *]:80:%1,http/[YOUR IP ADDRESS OR *]:80:www.%1 /physicalPath:%WebFile%%1
echo IIS Website Created:  %1  and  www.%1

#:: --------------------------------------------
#:: CREATE FTP in IIS
#:: --------------------------------------------
#%windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1"
#
#


#echo FTP SITE Created:  %1
echo ...
echo ...
echo New website added ========================= %1

Since in my case, not all the new sites will be live at once, I a default placeholder site who's contents are copied into the newly-created website directories.

This will add all sites to the default app pool.

That's about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文