Visual Studio 2010 Walkthrough: Editing Web Sites with FTP in Visual Studio Microsoft Visual Studio lets you read from and write to a remote server by using the File Transfer Protocol (FTP). The most common use for FTP Web sites is to update Web pages on a hosting site, which is faster than updating files that use an HTTP connection. After you connect to the FTP site in Visual Studio, you can create and edit files in those sites. For information about FTP, see FTP-Deployed Web Site Projects. Tasks illustrated in this walkthrough include the following:

Prerequisites
In order to complete this walkthrough, you will need the following: Access to a folder on an FTP server that supports the .NET Framework. If you have access to an existing FTP site, you can use that. For example, if you have an account that has a commercial hosting service that provides ASP.NET support, you can use that account in this walkthrough. Otherwise, you can configure a computer by running Microsoft Internet Information Services (IIS) as an FTP server. For more information about how to configure IIS as an FTP server, see How to: Create and Configure FTP Web Site Projects in IIS 6.0. Read and write permissions for the FTP directory on the server. Optionally, a virtual Web root that points to the FTP location. This lets you to test the files that you work with.
For purposes of this walkthrough, you can use a local copy of IIS as an FTP server. Ordinarily, you do not have to use FTP to communicate with the local copy of IIS.

Accessing the FTP Web Site Project
To start, you will connect to the FTP Web site project from within Visual Studio. You must know the FTP address of the FTP Web site and, if it is required, you must have a user name and password. To access the FTP Web site projectIn Visual Studio, on the File menu, click New Web Site. In the New Web Site dialog box, in the left-most Location list, click FTP Site, and then click Browse. In the Choose Location dialog box, in the Server and Directory boxes, enter the appropriate information. The Server field refers to the name or IP address of the FTP server. The Directory field refers to a specific directory on the FTP server that you want to put the content in. By default, many FTP sites connect you to a home directory, although there might still be a directory below that or a separate virtual directory where the Web content should be put. If you do not know these values, contact the FTP site administrator. For Port, the most common value is 21, but you should confirm that value with the FTP site administrator also. Examine the following values: Passive Mode. Leave this check box clear at first. Passive mode is sometimes required, such as if there is a firewall between your server and the FTP server. Anonymous Login. If the FTP site administrator has provided you with a user name and password, clear the Anonymous Login check box, and then in the Username and Password boxes, enter the appropriate information.
Click Open. Visual Studio will try to connect to the FTP server by using the information that you have provided. If the connection is successful, Visual Studio displays the FTP Web site name in Solution Explorer and lists the files that are already in the FTP Web site.
TroubleshootingIf the connection fails, examine the following: If you have administrative rights on the server, use IIS Manager to add the Write permission to the FTP virtual directory. Do not complete this before you have set restricted NTFS File System permissions on the virtual directory, either by using IIS Manager or Microsoft Windows Explorer. For more information, go to Microsoft Technet and search for information about how to help secure FTP sites. Confirm that the server name and directory name are correct. Use the URL of the Web site or the FTP site in the Server field and leave the Directory field blank. Try connecting with Passive Mode enabled. This frequently lets you get through a firewall. Make sure that the FTP Web site has the directory that you have indicated. If you are using IIS as the FTP server, remember that the directory is typically defined under the ftproot directory, not the wwwroot directory. Contact the FTP site administrator to determine whether anonymous log on is allowed. If not, make sure that you have credentials for a user account that has permission to access and modify the FTP directory.

Creating and Editing Pages
Working with Web pages in an FTP Web site is the same as working with Web pages in any other Web site. The only difference is that the files are stored on the FTP server, so that when you open or save the files, you are invoking the FTP connection. To create a pageIn Solution Explorer, right-click the FTP Web site name, click Add New Item, and then create a new Web Forms page. Note |
|---|
If you have access to the physical folder that is represented by the FTP Web site, you can confirm that the file is created in that folder. |
Switch to Design view. From the Standard group in the Toolbox, drag a Button control and a Label control onto the page. Double-click the Button control. The file contains a skeleton Click handler for the Button control. Replace the Click handler with the following code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "The FTP Web site is working!"
End Sub
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "The FTP Web site is working!";
}
Save your files.

Testing the FTP Web Site Project
If the FTP Web site has been set up to have an equivalent Web site, you can test the Web site by displaying it in the browser. To test the FTP Web site projectPress CTRL+F5. Visual Studio prompts you for the location to go to. The location is stored as part of the Web site configuration information. Enter the HTTP URL that points to the server and the Web virtual directory that you created in "Accessing the FTP Web Site," earlier in this walkthrough. For example, the URL might be the following: http://<server>/ExampleFtpFiles Note |
|---|
You can change or set the browser location at any time. To do this, in Solution Explorer, right-click the Web site name and then click Property Pages. On the Start Options tab, under Server, click Use custom server, and then in the Base URL box, type the location. |
The page is displayed in the browser. Close the browser.

See Also
|
Visual Studio 2010 チュートリアル: Visual Studio での FTP による Web サイトの編集 Microsoft Visual Studio を使用すると、ファイル転送プロトコル (FTP: File Transfer Protocol) を使用してリモート サーバーに対する読み書きができます。 FTP Web サイトは、ホスト サイトにある Web ページの更新によく使用されます。その方が、HTTP 接続を利用してファイルを更新するより速いからです。 Visual Studio で FTP サイトに接続したら、そのサイトでファイルを作成したり、編集したりできます。 FTP については、「FTP 配置された Web サイト プロジェクト」を参照してください。 このチュートリアルでは、以下のタスクを行います。

必須コンポーネント
このチュートリアルを完了するための要件は次のとおりです。 .NET Framework をサポートする FTP サーバー上のフォルダーへのアクセス。 既存の FTP サイトにアクセスできる場合は、それを使用できます。 たとえば、ASP.NET をサポートするホスト サービス プロバイダーのアカウントを開設している場合は、このチュートリアルでそのアカウントを使用できます。 利用できる既存の FTP サイトがない場合は、Microsoft Internet Information Services (IIS) を実行して、使用しているコンピューターを FTP サーバーとして構成できます。 IIS を使用して FTP サーバーを構成する方法の詳細については、「方法: IIS 6.0 内で FTP Web サイト プロジェクトを作成および構成する」を参照してください。 サーバーの FTP ディレクトリに対する読み取りアクセス許可と書き込みアクセス許可。 オプションで、FTP の場所を指す仮想 Web ルート。 対象ファイルのテストに使用します。
このチュートリアルの目的からは、IIS のローカル コピーを FTP サーバーとして使用できます。 通常は、IIS のローカル コピーとの通信に FTP を使用する必要はありません。

FTP Web サイト プロジェクトへのアクセス
まず、Visual Studio から FTP Web サイト プロジェクトに接続します。 そのためには、FTP Web サイトの FTP アドレスが必要となります。また、ログインのためのユーザー名とパスワードが必要となる場合もあります。 FTP Web サイト プロジェクトにアクセスするにはVisual Studio で [ファイル] メニューの [新しい Web サイト] をクリックします。 [新しい Web サイト] ダイアログ ボックスで、左端の [場所] ボックスの一覧の [FTP サイト] をクリックし、次に [参照] をクリックします。 [場所の選択] ダイアログ ボックスで、[サーバー] ボックスと [ディレクトリ] ボックスに、必要な情報を入力します。 [サーバー] フィールドには、FTP サーバーの名前か IP アドレスを入力します。 [ディレクトリ] フィールドには、FTP サーバー上のコンテンツを格納するためのディレクトリ名を入力します。 多くの FTP サイトでは、既定でホーム ディレクトリに接続されますが、Web コンテンツを格納するためのディレクトリがホーム ディレクトリの下にあったり、別の仮想ディレクトリである場合があります。 目的のディレクトリがわからない場合は、FTP サイトの管理者に相談してください。 ポート番号は、通常は 21 ですが、これについても FTP サイトの管理者に確認してください。 次の値を確認します。 [受動モード]。 最初は、このチェック ボックスはオフにします。 使用しているサーバーと FTP サーバーの間にファイアウォールが設定されている場合など、パッシブ モードを指定しなければならないことがあります。 [匿名ログイン]。 FTP サイト管理者からユーザー名とパスワードを提供された場合は、[匿名ログイン] チェック ボックスをオフにし、[ユーザー名] ボックスと [パスワード] ボックスに、提供された情報を入力します。
[開く] をクリックします。 Visual Studio が、入力した情報を基に FTP サーバーへの接続を試みます。 接続が確立されると、ソリューション エクスプローラーに FTP Web サイト名が表示され、FTP Web サイトにあるファイル名の一覧が表示されます。
トラブルシューティング接続に失敗した場合は、次の点を確認します。 サーバーの管理権限を与えられている場合は、IIS マネージャーを使用して FTP 仮想ディレクトリへの書き込みアクセス許可を追加します。 この操作を行う前に、IIS マネージャーまたは Microsoft Windows エクスプローラーを使用して、必ず仮想ディレクトリに対する制限付き NTFS ファイル システム アクセス許可を設定してください。 詳細については、「Microsoft Technet」にアクセスし、FTP サイトのセキュリティ保護に関する説明を検索してください。 サーバー名とディレクトリ名が正しいことを確認します。 [サーバー] フィールドに Web サイトまたは FTP サイトの URL を入力し、[ディレクトリ] フィールドは空白のままとします。 [受動モード] をオンにして接続を試みます。 多くの場合、これでファイアウォールを通過できます。 FTP Web サイトに、指定したディレクトリがあることを確認します。 IIS を FTP サーバーとして使用している場合は、通常は、このディレクトリは wwwroot ディレクトリではなく ftproot ディレクトリに定義されています。 匿名によるログオンが許可されるかどうかについては、FTP サイト管理者に相談してください。 許可されていない場合は、FTP ディレクトリにアクセスして変更するアクセス許可を持つユーザー アカウントの資格情報が自分自身に与えられていることを確認します。

ページの作成と編集
FTP Web サイトにある Web ページの操作方法は、他の Web サイトにある Web ページの操作方法と同じです。 唯一の違いは、ファイルが FTP サーバーに格納されていることで、そのため、ファイルを開いたり保存したりするときに FTP 接続を呼び出すことになります。 ページを作成するにはソリューション エクスプローラーで FTP Web サイトの名前を右クリックし、[新しい項目の追加] をクリックして、新しい Web フォーム ページを作成します。 メモ |
|---|
FTP Web サイトで表現されている物理的なフォルダーにアクセスできる場合は、ファイルがそのフォルダーに作成されたことを確認できます。 |
デザイン ビューに切り替えます。 ツールボックスの [標準] グループから、Button コントロールおよび Label コントロールをページにドラッグします。 Button コントロールをダブルクリックします。 このファイルには、Button コントロールのスケルトン Click ハンドラーが含まれています。 Click ハンドラーを次のコードで置き換えます。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "The FTP Web site is working!"
End Sub
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "The FTP Web site is working!";
}
ファイルを保存します。

FTP Web サイト プロジェクトのテスト
FTP Web サイトが、同じ内容の Web サイトを持つように設定されている場合は、ブラウザーでその Web サイトを表示して、テストできます。 FTP Web サイト プロジェクトをテストするにはCtrl + F5 キーを押します。 Visual Studio で目的の場所を入力するように求められます。 この場所は、Web サイト構成情報の一部として格納されます。 このチュートリアルの「FTP Web サイトへのアクセス」で作成したサーバーおよび Web 仮想ディレクトリを示す HTTP URL を入力します。 たとえば、URL は次のようになります。 http://<server>/ExampleFtpFiles メモ |
|---|
ブラウザーの場所は、いつでも変更したり、設定したりできます。 そのためには、ソリューション エクスプローラーで Web サイト名を右クリックし、[プロパティ ページ] をクリックします。 [開始オプション] タブの [サーバー] の下にある [カスタム サーバーを使用する] をクリックし、次に [基本 URL] ボックスに場所を入力します。 |
ブラウザーにページが表示されます。 ブラウザーを閉じます。

参照
|