ASP.NET: How to Create an FTP Web Site

    August 21, 2006

This article is an excerpt from the book: Murach’s ASP.NET 2.0 Web Programming with C# 2005.

An FTP web site is a web site that resides on a remote computer and that supports FTP file transfers. In most cases, FTP web sites are hosted on a server that you have access to over the Internet. In that case, the web site may already be set up for you. If not, you can use the Choose Location dialog box shown in figure 4-3 to create a new web site.

To display this dialog box, select FTP for the location option from the New Web Site dialog box, and click the Browse button. Then, enter the name of the server where you want to create the site and the path to the directory where the files for the web site will be stored. Note that except for the final directory, all the directories in the directory path must already exist. In this example, that means that the Murach directory must already exist. That’s because this directory maps to a virtual root that must be set up on the server. The virtual root works much like an IIS virtual directory. However, it points to the location where files are transferred to and from the server.

In addition to the server name and directory path, you can specify the port that Visual Studio should use to send commands to the server, you can specify whether the connection to the server is established using active or passive mode, and you can specify whether you’re logged in as an anonymous user or an authenticated user. In most cases, you’ll leave the port set at 21. However, you may need to change the Passive Mode and Anonymous Login options.

By default, Visual Studio uses active mode to establish a connection with the FTP server. To understand how active mode works, you need to realize that two ports are required to use FTP: one to transmit commands and one to transmit data. In active mode, Visual Studio connects to the server using the command port and then passes the address of the data port to be used to the server. Then, the server connects to Visual Studio using the data port.

The problem with using active mode is that if the client computer is behind a firewall, the server probably won’t be able to connect to it. In that case, you can connect to the server using passive mode. With passive mode, Visual Studio establishes the connections for both the command port and the data port. To use passive mode, just select the Passive Mode option.

In some cases, an FTP server will require that you provide a username and password to connect to the server. Then, you’ll need to remove the check mark from the Anonymous Login option and enter the required information in the Username and Password text boxes that become available. Note that because this information is saved until you end Visual Studio, you only need to enter it the first time you connect to the server during a Visual Studio session.

After you enter the required information into the Choose Location dialog box, you click the Open button to return to the New Web Site dialog box. When you do, the location will look something like this:


Then, you can just click the OK button to create the web site.

The dialog box for creating an FTP web site


To create a new FTP web site, select FTP from the Location drop-down list in the New Web Site dialog box. Then, click the Browse button to display the Choose Location dialog box shown above.

Enter the name of the server and the directory where you want to create the web site. You can typically leave the port set at 21.

Visual Studio can use either active mode or passive mode to establish connections to the FTP server. Active mode is the default. If the client is behind a firewall, though, you may need to use passive mode. To do that, select the Passive Mode option.

By default, Visual Studio logs you in to the FTP server as an anonymous user. However, some FTP servers require you to provide a username and password. In that case, you can deselect the Anonymous Login option and then enter your username and password. The username and password are saved until you end the Visual Studio session.

If you try to create a new FTP web site by entering a URL in the New Web Site dialog box, Visual Studio will display a dialog box that lets you specify whether you want to use passive mode and whether you want to log in as an anonymous user.

IIS can be configured to act as an FTP server as well as a web server. For more information, please see appendix A.


Add to | Digg | Yahoo! My Web | Furl

Bookmark WebProNews:

Joel Murach has been writing and editing for more than 10 years. During that time, he sharpened his programming skills as a contract programmer in San Francisco and his instructional skills as a trainer for HarperCollins Publishing. He always brings a vision to his projects that leads to improved effectiveness for his readers.