Sdílet prostřednictvím


Walkthrough: Editing Web Sites with FTP in Visual Web Developer

The Microsoft Visual Web Developer Web development tool 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 Web Developer, you can create and edit files in those sites. For information about FTP, see FTP-Deployed Web Sites.

Tasks illustrated in this walkthrough include the following:

  • Using FTP to connect to an existing Web site from within Visual Web Developer.

  • Creating and editing pages by using FTP.

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 Sites 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

To start, you will connect to the FTP Web site from within Visual Web Developer. 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

  1. In Visual Web Developer, on the File menu, click New Web Site.

  2. In the New Web Site dialog box, in the left-most Location list, click FTP Site, and then click Browse.

  3. 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.

  4. Examine the following values:

    • Passive Mode   

      Leave this check box clear at first. Passive mode is sometimes required, 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.

  5. Click Open.

    Visual Web Developer will try to connect to the FTP server by using the information that you have provided. If the connection is successful, Visual Web Developer displays the FTP Web site name in Solution Explorer and lists the files that are already in the FTP Web site.

Troubleshooting

If 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 page

  1. In 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.

  2. Switch to Design view.

  3. From the Standard group in the Toolbox, drag a Button control and a Label control onto the page.

  4. Double-click the Button control.

  5. The file contains a skeleton Click handler for the Button control.

  6. Complete the Click handler by adding the following highlighted 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!";
    }
    
  7. Save your files.

Testing the FTP Web Site

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 on the server

  1. Press CTRL+F5.

    Visual Web Developer prompts you for the location to go to. The location is stored as part of the Web site configuration information.

  2. 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.

  3. Close the browser.

See Also

Concepts

What's New in ASP.NET and Web Development

Types of Web Sites in Visual Web Developer