概觀
專案的 <Start><ftpServer> 方法會啟動套用至 的 <ftpServer> FTP 月臺。
<Start>呼叫 方法之後,FTP 月臺的執行時間狀態可以透過狀態屬性的值來決定。
相容性
| 版本 | 備註 |
|---|---|
| IIS 10.0 | 未在 IIS 10.0 中修改專案 <ftpServer> 。 |
| IIS 8.5 |
<ftpServer>IIS 8.5 中未修改包含 <Start> 方法的專案。 |
| IIS 8.0 |
<ftpServer>IIS 8.0 中未修改包含 <Start> 方法的專案。 |
| IIS 7.5 |
<ftpServer>包含 <Start> 作為 IIS 7.5 功能之方法的 元素。 |
| IIS 7.0 |
<ftpServer>包含 <Start> 方法的 元素是在 FTP 7.0 中引進,這是 IIS 7.0 的個別下載專案。 |
| IIS 6.0 | N/A |
安裝程式
若要支援 Web 服務器的 FTP 發佈,您必須安裝 FTP 服務。 若要這樣做,請使用下列步驟。
Windows Server 2012 或 Windows Server 2012 R2
在工作列上,按一下 [伺服器管理員]。
在[伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
在 [ 伺服器角色] 頁面上,展開 [ Web 服務器 (IIS) ],然後選取 [ FTP 伺服器]。
注意
支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,除了FTP 服務之外,您還需要選取[FTP 擴充性]。
螢幕擷取畫面。.按 [下一步],然後在 [ 選取功能 ] 頁面上,再次按 [ 下一步 ]。
在 [確認安裝選項] 頁面上,按一下 [安裝]。
在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或 Windows 8.1
在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
展開 [Internet Information Services],然後選取 [ FTP 伺服器]。
注意
支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
按一下 [確定]。
按一下 [關閉] 。
Windows Server 2008 R2
在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,展開[FTP 伺服器]。
選取 [FTP 服務]。
注意
支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
按一下 [下一步] 。
在 [確認安裝選項] 頁面上,按一下 [安裝]。
在 [結果] 頁面上,按一下 [關閉]。
Windows 7
在工作列上,按一下 [開始],然後按一下[主控台]。
在主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
展開 [Internet Information Services],然後展開 [ FTP 伺服器]。
選取 [FTP 服務]。
注意
支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
按一下 [確定]。
Windows Server 2008 或 Windows Vista
從下列 URL 下載安裝套件:
請遵循下列逐步解說中的指示來安裝 FTP 服務:
作法
如何啟動 FTP 網站
開啟 [Internet Information Services (IIS) 管理員:
如果您使用 Windows Server 2012 或 Windows Server 2012 R2:
- 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
如果您使用 Windows 8 或 Windows 8.1:
- 按住Windows鍵,按字母X,然後按一下[主控台]。
- 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
如果您使用 Windows Server 2008 或 Windows Server 2008 R2:
- 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
如果您使用 Windows Vista 或 Windows 7:
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager。
在 [ 連線] 窗格中,展開伺服器名稱、展開 [ 月臺] 節點,然後按一下 FTP 網站的名稱。
在 [動作] 窗格的 [管理網站] 區段中,按一下 [啟動]。
組態
月臺特定 <ftpServer> 專案是在月臺層級設定。
屬性
不適用。
子元素
不適用。
範例程式碼
下列範例可讓您以程式設計方式啟動 FTP 網站。
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
// Retrieve the sites collection.
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
// Locate a specific site.
ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"mySite");
if (siteElement == null) throw new InvalidOperationException("Element not found!");
// Create an object for the ftpServer element.
ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
// Create an instance of the Start method.
ConfigurationMethodInstance Start = ftpServerElement.Methods["Start"].CreateInstance();
// Execute the method to start the FTP site.
Start.Execute();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
{
foreach (ConfigurationElement element in collection)
{
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
{
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2)
{
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null)
{
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
{
matches = false;
break;
}
}
if (matches)
{
return element;
}
}
}
return null;
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
' Retrieve the sites collection.
Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
' Locate a specific site.
Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "mySite")
If (siteElement Is Nothing) Then
Throw New InvalidOperationException("Element not found!")
End If
' Create an object for the ftpServer element.
Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer")
' Create an instance of the FlushLog method.
Dim Start As ConfigurationMethodInstance = ftpServerElement.Methods("Start").CreateInstance()
' Execute the method to start the FTP site.
Start.Execute()
End Sub
Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
For Each element As ConfigurationElement In collection
If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
Dim matches As Boolean = True
Dim i As Integer
For i = 0 To keyValues.Length - 1 Step 2
Dim o As Object = element.GetAttributeValue(keyValues(i))
Dim value As String = Nothing
If (Not (o) Is Nothing) Then
value = o.ToString
End If
If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
matches = False
Exit For
End If
Next
If matches Then
Return element
End If
End If
Next
Return Nothing
End Function
End Module
JavaScript
// Create a Writable Admin Manager object.
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
// Retrieve the sites collection.
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites","MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;
// Locate a specific site.
var siteElementPos = FindElement(sitesCollection,"site",["name","MySite"]);
if (siteElementPos == -1) throw "Element not found!";
// Retrieve the site element.
var siteElement = sitesCollection.Item(siteElementPos);
// Create an object for the ftpServer element.
var ftpServerElement = siteElement.ChildElements.Item("ftpServer");
// Create an instance of the start method.
var Start = ftpServerElement.Methods.Item("Start").CreateInstance();
// Execute the method to start the FTP site.
Start.Execute();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
VBScript
' Create a Writable Admin Manager object.
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
' Retrieve the sites collection.
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites","MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection
' Locate a specific site.
siteElementPos = FindElement(sitesCollection,"site",Array("name","MySite"))
If siteElementPos = -1 Then
WScript.Echo "Element not found!"
WScript.Quit
End If
' Retrieve the site element.
Set siteElement = sitesCollection.Item(siteElementPos)
' Create an object for the ftpServer element.
Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")
' Create an instance of the Start method.
Set Start = ftpServerElement.Methods.Item("Start").CreateInstance()
' Execute the method to start the FTP site.
Start.Execute()
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function