Recipe 12.24. Creating FTP SitesProblemYou want to create an FTP site. SolutionUsing a graphical user interfaceFirst, you need to install the FTP service:
To create a new FTP site from scratch using a wizard, do the following:
To create a new FTP site using a previously saved configuration file, do the following:
Using a command-line interfaceThe 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 DiscussionWhen 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 VBScriptThis 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 AlsoRecipe 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) |