Recipe12.24.Creating FTP Sites


Recipe 12.24. Creating FTP Sites

Problem

You want to create an FTP site.

Solution

Using a graphical user interface

First, you need to install the FTP service:

  1. From the Start menu, select Control Panel Add or Remove Programs.

  2. Click Add/Remove Windows Components.

  3. Select the checkbox for Application Server and click Details.

  4. Select the checkbox for Internet Information Services (IIS) and click Details.

  5. Select the checkbox for File Transfer Protocol (FTP) Service, click OK twice, and then Next.

  6. Click Finish after the wizard completes.

To create a new FTP site from scratch using a wizard, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the server node in the console tree.

  3. Right-click on the FTP Sites node, select New Next.

  4. Type a descriptive name for your site and click Next.

  5. Assign an IP address to your site and click Next.

  6. Select the option Do not isolate users and click Next.

  7. Specify the path to the FTP home directory for your site and click Next.

  8. Specify access permissions to control access to your site and click Next then Finish.

To create a new FTP site using a previously saved configuration file, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the server node in the console tree.

  3. Right-click on the FTP Sites node and select New

    Specify the path to the XML file containing your saved IIS configuration, click Read File, select the FTP site you want to import, and click OK.

  4. If prompted for a password, enter it and click OK.

  5. In the left pane, right-click on the new FTP site and select Start.

Using a command-line interface

The following command creates a new FTP site named My FTP Site with root directory C:\ftpstuff and IP address 172.16.12.50, and leaves the site in a stopped state:

> iisftp /create C:\ftpstuff "My FTP Site" /i 172.16.12.50 /dontstart

To start the new site, do the following:

> iisftp /start "My FTP Site"

You can also stop and start all FTP sites on your server using the following commands:

> net stop msftpsvc > net start msftpsvc

To display a list of all FTP sites on your server, use the following command:

> iisftp /query

Using VBScript
' This code creates a ftp site. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>"   ' computer to connect to strSiteName = "<SiteName>"     ' web site description strRootDir = "<RootDirectory>" ' root directory for the ftp site strPort = "21"                 ' port for the web site ' The following parameters are optional ' strIP = "<IPAddress>"        ' IP address used for the site ' strHostHeader = "<HostName>" ' host header name for the site strSiteID = "<SiteID>"         ' site ID (default is to auto-generate) ' ------ END CONFIGURATION --------- set objIIS = GetObject("IIS://" & strComputer & "/msftpsvc" ) set objNewFtpServer = objIIS.Create("IIsFtpServer",strSiteID) objNewFtpServer.ServerComment = strSiteName objServerBindings = Array(0) objServerBindings(0) = strIP & ":" & strPort & ":" & strHostHeader objNewFtpServer.ServerBindings = objServerBindings objNewFtpServer.SetInfo     set objNewDir = objNewFTPServer.Create("IIsFtpVirtualDir", "ROOT") objNewDir.Path = strRootDir objNewDir.AccessRead = True objNewDir.SetInfo     WScript.Echo "Successfully created ftp site " & objNewFtpServer.ServerComment

Discussion

When you install the FTP Service component of IIS, a Default FTP Site is automatically created. Like the Default Web Site, this FTP site listens on all unassigned IP addresses, if you only need one FTP site, you can customize this one (for example, by specifying content location, configuring authentication methods, specifying a directory listing style, and so on) instead of creating additional new FTP sites. You can also use the iisftp.vbs command script to create virtual directories for FTP sites. The syntax of this command is similar to the iisvdir.vbs script used to create virtual directories for web sites (discussed in Recipe 12.5). Be sure to see MS KB 142853 mentioned below for a difference in how virtual directories work with FTP vs. web sites.

Using VBScript

This code is similar, though not identical, to the code for creating a web site shown in Recipe 12.5. There are a couple of notable differences. First, instead of calling a CreateNewSite method, it calls Create and passes IIsFtpServer and the site ID to it. That method returns an object that represents the new FTP site. It then modifies several properties including ServerBindings (see Recipe 12.5). After that, the script calls SetInfo to commit the changes, but we still aren't quite done.

By default, there are no virtual directories configured for new FTP sites, so we have to create our own. I call the Create method against the new FTP server object and set up the directory (note that this doesn't actually create the directory on the filesystem).

See Also

Recipe 12.5, MS KB 323384 (How To Set Up an FTP Server in Windows Server 2003), MS KB 311669 (IIS: MMC for FTP Site Does Not Display Files or Folders in the Right Pane), MS KB 142853 (Virtual Directories Not Visible on FTP Clients), and MS KB 814865 (INFO: FTP Site Administration Documentation in IIS 6.0)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net