WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Creating IIS 5 FTP Users

 Keywords: Create IIS 5.0 FTP User 

Question:

I need some background and whether this can be done in Winbatch (I think it can).

We distribute reports to users of our website in PDF format. We also zip and password protect these PDF files and e-mail them to users. They are complaining this is taking too long to decrypt each e-mailed report (could be numerous reports per day) and they want an easier way to get the reports (they can also be viewed after logging into our site but this 'takes too long'). Our policy is that any sensitive information must be sent over an SSL connection or be encrypted with at least Winzip and a password or preferrably PGP.

We're hesitant to batch up reports in the zip since e-mail systems have a size limitation and our users are NOT knowledgable - trust me on this one! Anyway, I was thinking about putting the PDF files in an FTP folder created for that user and allowing them to use FTP to get the files.

Now the real question: Is it possible for Winbatch to create the folder for and set the security attributes for a particular user under IIS 5.0? In other words, can I pass the name of the folder to create, the usercode/password to use to Winbatch and have Winbatch interface with the FTP services manager to create the secured folder? What extender(s) would be involved and what functions would I use?

Answer:

Creating IIS 5 FTP users....Yes, It can be done. I have a script that re-creates our FTP server for disaster recovery. You need the NT Networking extender, and the ADSI extender.

Attached is some example code taken from that script. The sample creates a single FTP account.

;IIS5ADD.WBT
;------------------------------------------------------------------
;
;  Create a user's mailbox for IIS 5.0
;
;------------------------------------------------------------------
  UserID =  "TheUserID"
  UserPW =  "ThePassword" ; Not required if the ID already exists
  UserComment = "Some comment about this user" ; optional

;------------------------------------------------------------------   
;  We need to know which OS we're running under.
;------------------------------------------------------------------
  X=WinVersion(5)
  if X == "1-4-0"  then OS="9x"
  if X == "1-4-10" then OS="9x"
  if X == "1-4-90" then OS="9x"
  if X == "2-3-51" then OS="3"
  if X == "2-4-0"  then OS="NT"
  if X == "2-5-0"  then OS="2K"
  if X == "2-5-1"  then OS="XP"

  if !(OS == "NT" || OS == "2K")
      Message("Sorry",StrCat("Cannot Proceed.",@CRLF,@CRLF,"This program must be run on Windows NT or Windows 2000.")
      return
  endif

;------------------------------------------------------------------
;  We need these two extenders
;------------------------------------------------------------------  
AddExtender("wwwnt34i.dll")    ; NT Networking 
AddExtender("C:\Documents and settings\Kreutza\Desktop\z\WWADS34I.dll")    ; ADSI

;-----------------------------------------
;  Get the root directory for IIS FTP
;-----------------------------------------  
FtpRoot = dsGetProperty("IIS://Localhost/MSFTPSVC/1/ROOT","Path")
if StrTrim(FtpRoot) == ""
    Message("Sorry","Can't find the FTP root path on this machine.")
    return
endif
  
;------------------------------------------
; Create the userid (if it doesn't exist
;------------------------------------------
if  wntUserExist("",UserID) == @FALSE
    Message("","Creating a new user")
    wntUserAddDat("name",UserID) 
    wntUserAddDat("password",UserPW) 
    wntUserAddDat("flags",1+512+65536)
                         ;  1 = Normal account
                         ; 512 = UF_NORMAL_ACCOUNT
                         ; 65536 = Don't expire password
    wntUserAddDat("acct_expires","0000:00:00:00:00:00")
    wntUserAddDat("comment",UserComment)
    wntUserAdd("")
endif

;------------------------------------------------------
;  We add all DTP users into a user group
;-------------------------------------------------------
wntMemberSet("","Group_For_FTP",UserID,@LOCALGROUP)

;------------------------------------------------------
;  Create an FTP directory for this user.
;  Give access permissions to administrators, 
;  the SYSTEM group, and the user.
;-------------------------------------------------------  
NewDir = StrCat(FTPRoot,"\",UserID)
DirMake(NewDir)
wntAccessAdd("",NewDir,"administrators",300,"Dir:Full")
wntAccessAdd("",NewDir,"SYSTEM",300,"Dir:Change")
wntAccessAdd("",NewDir,UserID,300,"Dir:Modify")

if OS == "2K"
      wntAccessMod("",NewDir,300,2,1)
endif
  
;------------------------------------------------------
;  Now add the user to the IIS database
;------------------------------------------------------
if dsisObject(StrCat("IIS://Localhost/MSFTPSVC/1/ROOT/",UserID))
    dsDeleteObj(StrCat("IIS://Localhost/MSFTPSVC/1/ROOT/",UserID))
endif
NewObject = dsCreateObj("IIS://Localhost/MSFTPSVC/1/ROOT","IIsFtpVirtualDir",UserID)
dsSetProperty(NewObject,"Path",NewDir)
dsSetProperty(NewObject,"AccessFlags",3)
dsSetProperty(NewObject,"AccessRead",-1)
dsSetProperty(NewObject,"AccessWrite",-1)
dsSetProperty(NewObject,"DontLog",0)
dsSetObj(NewObject)
Return

Article ID:   W15807
File Created: 2004:03:30:15:40:56
Last Updated: 2004:03:30:15:40:56