Using Virtual Directories with FTP Sites

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2, Windows Server 2008

Overview and procedures for creating and deleting virtual directories for FTP sites using IIS Manager and command-line scripts.

A virtual directory is a friendly name, or alias, either for a physical directory on your server hard disk that does not usually reside under the FTP site's home directory. The use of aliases is secure because users do not know where your files are physically located on the server relative to the FTP site's home directory, and therefore cannot use that information to attempt to modify your files. Aliases also make it easier for you to move directories in your site. Rather than changing the URL for the directory, you need only change the mapping between the alias and the physical location of the directory.

Another advantage of aliases is that you can publish content in multiple directories, to be accessed by all users, and control read/write permissions for each virtual directory separately. Even with User Isolation enabled, you can share public content by creating a virtual directory with access permission for all users.

If your FTP site contains files that are located in a directory other than the home directory, or on other computers, you must create virtual directories to include those files in your FTP site. To create a virtual directory that points to a physical directory on another computer, you must specify the full UNC path to the directory, and provide a user name and password for user rights.

If you want to publish from any directory not contained within your home directory, you must create a virtual directory. For example, suppose you are setting up a FTP site for your marketing team on your company's intranet. The following table shows an example of how you might construct the mapping between the physical location of the files and the URL that accesses the files.

URL Physical Location Alias

ftp://SampleFTPSite

C:\Inetpub\Ftproot

home directory

ftp://SampleFTPSite/PR

C:\Marketing\PublicRel

PR

ftp://SampleFTPSite/PR/OldPR

C:\Documents\Old

OldPR

ftp://SampleFTPSite/PRPublic

C:\Documents\Public

PRPublic

ftp://SampleWebSite/Customers

//Server2/SalesData

Customers

Both virtual directories and physical directories (directories without an alias) appear in IIS Manager. A modified folder icon indicates a virtual directory. The following illustration shows the FTP site example described above, where Customers, PR, and PRPublic are virtual directories.

Art Image

You can also define nested virtual directories. For example, within the PR virtual directory, you can create another virtual directory, for example, named Oldpr. The content in Oldpr is accessible using the URL ftp://SampleFTPSite/PR/Oldpr.

Note

The FTP server does not include the names of any virtual directories when the content of the current working directory is requested by a client application. Physical directories, however, are listed.

Important

Access to the content of a virtual directory depends on the current working directory. For example, if a user is connected to the root directory of SampleFTPSite, assuming that the user has the necessary permissions, the user can change the working directory to the following paths: /PRPublic, /PR, /PR/Oldpr, and /Customers only if the user knows the site structure. For example, if the current working directory is /PRPublic, the user will receive an error message when attempting to change the working directory to /PR by typing the command cwd /PR, but will successfully change the working directory to /PR by typing the command cwd ./PR.

Also, a user can use a combination of physical directory names and virtual directory names to change the working directory. For example, assume that under the physical path to which the PR virtual directory is mapped, there is a physical folder named Test, and the current working directory is the root of SampleFTPSite. The user can change the working directory to the physical Test folder using the command cwd PR/Test.

For a basic FTP site, you can place all of your files in the site's home directory, and most likely do not need to add virtual directories. If you have a complex site, or want to specify different URLs for different parts of your site, you can add virtual directories as needed. To make a virtual directory accessible from multiple sites, you must add the virtual directory to each site.

There are two ways to create or delete a virtual directory:

  • Using IIS Manager.

  • Using the iisftpdr.vbs administration script.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /User:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.msc".

Procedures

To create a virtual directory using IIS Manager

  1. In IIS Manager, expand the local computer, expand the FTP Sites folder, expand the FTP site to which you want to add a virtual directory, right-click the site or folder within which you wish to create the virtual directory, point to New, and then click Virtual Directory.

  2. Click Next.

  3. In the Alias box, type a name for the virtual directory, and click Next. This is the name the user types, and should be short and easy to type.

  4. In the Directory box, type or browse to the physical directory in which the virtual directory resides, and click Next.

  5. Under Allow the following permissions, select the check boxes next to the access permissions appropriate to your needs, and click Next.

  6. Click Finish. The virtual directory is created below the currently selected folder level.

Important

You must be a member of the Administrators group on the local computer to run scripts and executables. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas /profile /User:MyComputer\Administrator cmd to open a command window with administrator rights and then type cscript.exeScriptName (include the script's full path and any parameters).

To create a virtual directory using the Iisftpdr.vbs administration script

  1. From the Start menu, click Run.

  2. In the Open box, type cmd, and click OK.

  3. At the command prompt, type cscript iisftpdr.vbs /create SampleFTPSite VirtualDirectoryName x:**\**path, and press ENTER. Substitute your FTP site name, virtual directory name, and path to the physical directory as appropriate.

Note

Deleting a virtual directory does not delete the corresponding physical directory or files.

To delete a virtual directory using IIS Manager

  • In IIS Manager, expand the FTP site containing the virtual directory you want to delete, right-click the virtual directory, click Delete, and then click Yes.

Note

The below method does not work for root virtual directories.

To delete a virtual directory using the Iisftpdr.vbs administration script

  1. From the Start menu, click Run.

  2. In the Open box, type cmd, and click OK.

  3. At the command prompt, type cscript iisftpdr.vbs /delete SampleFTPSite VirtualDirectoryName, and press ENTER. Substitute Your FTP site name and virtual directory name as appropriate.