Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1091 lines
40 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsFtp.vbs
  7. '
  8. Option Explicit
  9. On Error Resume Next
  10. ' Error codes
  11. Const ERR_OK = 0
  12. Const ERR_GENERAL_FAILURE = 1
  13. '''''''''''''''''''''
  14. ' Messages
  15. Const L_BindingConflict_ErrorMessage = "(ERROR: BINDING CONFLICT)"
  16. Const L_SitesNotFound_ErrorMessage = "Site(s) not found."
  17. Const L_IsAlready_Message = "is already"
  18. Const L_ServerIs_Message = "server is"
  19. Const L_HasBeen_Message = "has been"
  20. Const L_NotFound_Message = "not found"
  21. Const L_All_Text = "ALL"
  22. Const L_AllUnassigned_Text = "ALL UNASSIGNED"
  23. Const L_NotSpecified_Text = "NOT SPECIFIED"
  24. Const L_Server_Text = "Server"
  25. Const L_SiteName_Text = "Site Name"
  26. Const L_MetabasePath_Message = "Metabase Path"
  27. Const L_IP_Text = "IP"
  28. Const L_Port_Text = "Port"
  29. Const L_Root_Text = "Root"
  30. Const L_Status_Text = "Status"
  31. Const L_NA_Text = "N/A"
  32. Const L_Error_ErrorMessage = "Error"
  33. Const L_GetRoot_ErrorMessage = "Could not obtaing ROOT virtual dir of site"
  34. Const L_SiteGet_ErrorMessage = "Could not obtain ftp site"
  35. Const L_Stop_ErrorMessage = "Could not stop ftp site"
  36. Const L_SiteDel_ErrorMessage = "Could not delete ftp site"
  37. Const L_GetFtpServer_ErrorMessage = "Error trying to obtain FtpServer object."
  38. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory"
  39. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the '<drive>:\<path>' format."
  40. Const L_CannotStart_Message = "Server cannot be started in its current state"
  41. Const L_CannotStop_Message = "Server cannot be stopped in its current state"
  42. Const L_CannotPause_Message = "Server cannot be paused in its current state"
  43. Const L_CannotControl_ErrorMessage = "Server cannot be controled in its current state"
  44. Const L_FailChange_ErrorMessage = "Failed to change status of server."
  45. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  46. Const L_MinInfoNeeded_ErrorMessage = "Need at least <root> to create a site."
  47. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  48. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  49. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  50. Const L_ServerInstance_ErrorMessage = "Error trying to create a new ftp server instance."
  51. Const L_ServerPut_ErrorMessage = "Error trying to save new ftp server instance."
  52. Const L_VDirInstance_ErrorMessage = "Error trying to create a new virtual directory instance."
  53. Const L_VDirPut_ErrorMessage = "Error trying to save new virtual directory instance."
  54. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  55. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  56. Const L_CmdLib_ErrorMessage = "Unable to create instance of the CmdLib object."
  57. Const L_InvalidIP_ErrorMessage = "Invalid IP Address. Please check if it is well formated and belongs to this machine."
  58. Const L_InvalidPort_ErrorMessage = "Invalid port number."
  59. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  60. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  61. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  62. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: "
  63. '''''''''''''''''''''
  64. ' Help
  65. ' General help messages
  66. Const L_SeeHelp_Message = "Type IIsFtp /? for help."
  67. Const L_SeeStartHelp_Message = "Type IIsFtp /start /? for help."
  68. Const L_SeeStopHelp_Message = "Type IIsFtp /stop /? for help."
  69. Const L_SeePauseHelp_Message = "Type IIsFtp /pause /? for help."
  70. Const L_SeeCreateHelp_Message = "Type IIsFtp /create /? for help."
  71. Const L_SeeDeleteHelp_Message = "Type IIsFtp /delete /? for help."
  72. Const L_SeeQueryHelp_Message = "Type IIsFtp /query /? for help."
  73. Const L_Help_HELP_General01_Text = "Description: Start, Stop, Pause, Delete, Query, or Create a Ftp Site"
  74. Const L_Help_HELP_General02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /<operation>"
  75. Const L_Help_HELP_General03_Text = " [arguments]"
  76. Const L_Help_HELP_General04_Text = "Parameters:"
  77. Const L_Help_HELP_General05_Text = ""
  78. Const L_Help_HELP_General06_Text = "Value Description"
  79. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  80. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  81. Const L_Help_HELP_General09_Text = " [Default: current user]"
  82. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  83. Const L_Help_HELP_General11_Text = "<operation> /start Starts a site(s) on given IIS Server."
  84. Const L_Help_HELP_General12_Text = " /stop Stops a site(s) from running on a given"
  85. Const L_Help_HELP_General13_Text = " IIS Server."
  86. Const L_Help_HELP_General14_Text = " /pause Pauses a site(s) that is running on a"
  87. Const L_Help_HELP_General15_Text = " given IIS Server."
  88. Const L_Help_HELP_General18_Text = " /delete Deletes IIS configuration from an existing"
  89. Const L_Help_HELP_General19_Text = " Ftp Site. Content will not be deleted."
  90. Const L_Help_HELP_General20_Text = " /create Creates a Ftp Site."
  91. Const L_Help_HELP_General21_Text = " /query Queries existing Ftp Sites."
  92. Const L_Help_HELP_General22_Text = "For detailed usage:"
  93. Const L_Help_HELP_General23_Text = "IIsFtp /start /?"
  94. Const L_Help_HELP_General24_Text = "IIsFtp /stop /?"
  95. Const L_Help_HELP_General25_Text = "IIsFtp /pause /?"
  96. Const L_Help_HELP_General27_Text = "IIsFtp /delete /?"
  97. Const L_Help_HELP_General28_Text = "IIsFtp /create /?"
  98. Const L_Help_HELP_General29_Text = "IIsFtp /query /?"
  99. ' Common to all status change commands
  100. Const L_Help_HELP_Status03_Text = "Parameters:"
  101. Const L_Help_HELP_Status09_Text = "<ftpsite> Use either the site name or metabase path to specify"
  102. Const L_Help_HELP_Status09p1_Text = " the site"
  103. Const L_Help_HELP_Status10_Text = "Examples:"
  104. ' Start help messages
  105. Const L_Help_HELP_Start01_Text = "Description: Starts a site(s) on a given IIS Server."
  106. Const L_Help_HELP_Start02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /start"
  107. Const L_Help_HELP_Start02p1_Text = " <ftpsite> [<ftpsite> ...]"
  108. Const L_Help_HELP_Start11_Text = "IIsFtp /start ""Default Ftp Site"""
  109. Const L_Help_HELP_Start12_Text = "IIsFtp /start msftpsvc/1"
  110. Const L_Help_HELP_Start13_Text = "IIsFtp /start w3svc/2 ""Default Ftp Site"" w3svc/10"
  111. Const L_Help_HELP_Start14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /start msftpsvc/4"
  112. ' Stop help messages
  113. Const L_Help_HELP_Stop01_Text = "Description: Stops a site(s) on a given IIS Server."
  114. Const L_Help_HELP_Stop02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /stop"
  115. Const L_Help_HELP_Stop02p1_Text = " <ftpsite> [<ftpsite> ...]"
  116. Const L_Help_HELP_Stop11_Text = "IIsFtp /stop ""Default Ftp Site"""
  117. Const L_Help_HELP_Stop12_Text = "IIsFtp /stop msftpsvc/1"
  118. Const L_Help_HELP_Stop13_Text = "IIsFtp /stop w3svc/2 ""Default Ftp Site"" w3svc/10"
  119. Const L_Help_HELP_Stop14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /stop msftpsvc/4"
  120. ' Pause help messages
  121. Const L_Help_HELP_Pause01_Text = "Description: Pauses a site(s) on a given IIS Server."
  122. Const L_Help_HELP_Pause02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /pause"
  123. Const L_Help_HELP_Pause02p1_Text = " <ftpsite> [<ftpsite> ...]"
  124. Const L_Help_HELP_Pause11_Text = "IIsFtp /pause ""Default Ftp Site"""
  125. Const L_Help_HELP_Pause12_Text = "IIsFtp /pause msftpsvc/1"
  126. Const L_Help_HELP_Pause13_Text = "IIsFtp /pause w3svc/2 ""Default Ftp Site"" w3svc/10"
  127. Const L_Help_HELP_Pause14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /pause msftpsvc/4"
  128. ' Delete help messages
  129. Const L_Help_HELP_Delete01_Text = "Description: Deletes IIS configuration for an existing ftp site. Content"
  130. Const L_Help_HELP_Delete01p1_Text = " will not be deleted."
  131. Const L_Help_HELP_Delete02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /delete"
  132. Const L_Help_HELP_Delete02p1_Text = " <ftpsite> [<ftpsite> ...]"
  133. Const L_Help_HELP_Delete11_Text = "IIsFtp /delete ""Default Ftp Site"""
  134. Const L_Help_HELP_Delete12_Text = "IIsFtp /delete msftpsvc/1"
  135. Const L_Help_HELP_Delete13_Text = "IIsFtp /delete w3svc/2 ""Default Ftp Site"" w3svc/10"
  136. Const L_Help_HELP_Delete14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /delete msftpsvc/4"
  137. ' Create help messages
  138. Const L_Help_HELP_Create01_Text = "Description: Creates a ftp site."
  139. Const L_Help_HELP_Create02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /create <root>"
  140. Const L_Help_HELP_Create02p1_Text = " <name> [/b <port>] [/i <ip>] [/dontstart]"
  141. Const L_Help_HELP_Create09_Text = "<root> Root directory for the new server. If this directory"
  142. Const L_Help_HELP_Create09p1_Text = " does not exist, it will be created."
  143. Const L_Help_HELP_Create10_Text = "<name> The name that appears in the Microsoft Management"
  144. Const L_Help_HELP_Create10p1_Text = " Console (MMC)."
  145. Const L_Help_HELP_Create12_Text = "/b <port> The number of the port to which the new server should"
  146. Const L_Help_HELP_Create12p1_Text = " bind. [Default: 21]"
  147. Const L_Help_HELP_Create13_Text = "/i <ip> The IP address to assign to the new server."
  148. Const L_Help_HELP_Create13p1_Text = " [Default: All Unassigned]"
  149. Const L_Help_HELP_Create15_Text = "/dontstart Don't start this site after it is created."
  150. Const L_Help_HELP_Create22_Text = "IIsFtp /create c:\inetpub\ftproot ""My Site"" /b 21"
  151. Const L_Help_HELP_Create23_Text = "IIsFtp /s Server1 /u Administrator /p p@assWOrd /create c:\inetpub\ftproot"
  152. Const L_Help_HELP_Create23p1_Text = " ""My Site"""
  153. Const L_Help_HELP_Create24_Text = "IIsFtp /create c:\inetpub\ftproot ""My Site"" /i 172.30.163.244 /b 21"
  154. ' Query help messages
  155. Const L_Help_HELP_Query01_Text = "Description: Queries existing ftp sites."
  156. Const L_Help_HELP_Query02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /query"
  157. Const L_Help_HELP_Query02p1_Text = " [<ftpsite> ...]"
  158. Const L_Help_HELP_Query11_Text = "IIsFtp /query ""Default Ftp Site"""
  159. Const L_Help_HELP_Query12_Text = "IIsFtp /query msftpsvc/1"
  160. Const L_Help_HELP_Query13_Text = "IIsFtp /query"
  161. Const L_Help_HELP_Query14_Text = "IIsFtp /query ""Default Ftp Site"" ""Sample Site"" msftpsvc/1"
  162. Const L_Help_HELP_Query15_Text = "IIsFtp /s Server1 /u Administrator /p p@ssW0rd /query ""Default Ftp Site"""
  163. ' Status
  164. Const L_Started_Text = "started"
  165. Const L_Stopped_Text = "stopped"
  166. Const L_Paused_Text = "paused"
  167. Const L_Continued_Text = "continued"
  168. Const L_Deleted_Text = "deleted"
  169. ''''''''''''''''''''''''
  170. Dim SiteStatus
  171. SiteStatus = Array("", "", L_Started_Text, "", L_Stopped_Text, "", L_Paused_Text, L_Continued_Text, L_Deleted_Text)
  172. ' Operation codes
  173. Const OPER_START = 1
  174. Const OPER_STOP = 2
  175. Const OPER_PAUSE = 3
  176. Const OPER_DELETE = 4
  177. Const OPER_CREATE = 5
  178. Const OPER_QUERY = 6
  179. ' ServerState codes
  180. Const SERVER_STARTING = 1
  181. Const SERVER_STARTED = 2
  182. Const SERVER_STOPPING = 3
  183. Const SERVER_STOPPED = 4
  184. Const SERVER_PAUSING = 5
  185. Const SERVER_PAUSED = 6
  186. Const SERVER_CONTINUING = 7
  187. '
  188. ' Main block
  189. '
  190. Dim oScriptHelper, oCmdLib
  191. Dim strServer, strUser, strPassword, strSite
  192. Dim intOperation, intResult
  193. Dim strRoot, strName, strPort, strIP
  194. Dim bDontStart
  195. Dim aArgs, arg
  196. Dim strCmdLineOptions
  197. Dim oError
  198. ' Default values
  199. strServer = "."
  200. strUser = ""
  201. strPassword = ""
  202. intOperation = 0
  203. strSite = ""
  204. strName = ""
  205. bDontStart = False
  206. ' Instantiate script helper object
  207. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  208. If Err.Number <> 0 Then
  209. WScript.Echo L_ScriptHelper_ErrorMessage
  210. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  211. WScript.Quit(ERR_GENERAL_FAILURE)
  212. End If
  213. Set oScriptHelper.ScriptHost = WScript
  214. ' Check if we are being run with cscript.exe instead of wscript.exe
  215. oScriptHelper.CheckScriptEngine
  216. ' Minimum number of parameters must exist
  217. If WScript.Arguments.Count < 1 Then
  218. WScript.Echo L_NotEnoughParams_ErrorMessage
  219. WScript.Echo L_SeeHelp_Message
  220. WScript.Quit(ERR_GENERAL_FAILURE)
  221. End If
  222. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];start::n;stop::n;pause::n;delete::n;" & _
  223. "[create:c:1;port:b:1;ip:i:1;dontstart::0];query:q:n"
  224. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  225. If Not oError Is Nothing Then
  226. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  227. ' Not enough arguments for a specified switch
  228. WScript.Echo L_NotEnoughParams_ErrorMessage
  229. If oError.SwitchName = "create" Then
  230. WScript.Echo L_SeeCreateHelp_Message
  231. Else
  232. WScript.Echo L_SeeHelp_Message
  233. End If
  234. Else
  235. ' Invalid switch
  236. WScript.Echo L_InvalidSwitch_ErrorMessage & oError.SwitchName
  237. WScript.Echo L_SeeHelp_Message
  238. End If
  239. WScript.Quit(ERR_GENERAL_FAILURE)
  240. End If
  241. If oScriptHelper.GlobalHelpRequested Then
  242. DisplayHelpMessage
  243. WScript.Quit(ERR_OK)
  244. End If
  245. For Each arg In oScriptHelper.Switches
  246. Select Case arg
  247. Case "server"
  248. ' Server information
  249. strServer = oScriptHelper.GetSwitch(arg)
  250. Case "user"
  251. ' User information
  252. strUser = oScriptHelper.GetSwitch(arg)
  253. Case "password"
  254. ' Password information
  255. strPassword = oScriptHelper.GetSwitch(arg)
  256. Case "start"
  257. If (intOperation <> 0) Then
  258. WScript.Echo L_OnlyOneOper_ErrorMessage
  259. WScript.Echo L_SeeHelp_Message
  260. WScript.Quit(ERR_GENERAL_FAILURE)
  261. End If
  262. intOperation = OPER_START
  263. If oScriptHelper.IsHelpRequested(arg) Then
  264. DisplayStartHelpMessage
  265. WScript.Quit(ERR_OK)
  266. End If
  267. aArgs = oScriptHelper.GetSwitch(arg)
  268. If UBound(aArgs) = -1 Then
  269. WScript.Echo L_NotEnoughParams_ErrorMessage
  270. WScript.Echo L_SeeStartHelp_Message
  271. WScript.Quit(ERR_GENERAL_FAILURE)
  272. End If
  273. Case "stop"
  274. If (intOperation <> 0) Then
  275. WScript.Echo L_OnlyOneOper_ErrorMessage
  276. WScript.Echo L_SeeHelp_Message
  277. WScript.Quit(ERR_GENERAL_FAILURE)
  278. End If
  279. intOperation = OPER_STOP
  280. If oScriptHelper.IsHelpRequested(arg) Then
  281. DisplayStopHelpMessage
  282. WScript.Quit(ERR_OK)
  283. End If
  284. aArgs = oScriptHelper.GetSwitch(arg)
  285. If UBound(aArgs) = -1 Then
  286. WScript.Echo L_NotEnoughParams_ErrorMessage
  287. WScript.Echo L_SeeStopHelp_Message
  288. WScript.Quit(ERR_GENERAL_FAILURE)
  289. End If
  290. Case "pause"
  291. If (intOperation <> 0) Then
  292. WScript.Echo L_OnlyOneOper_ErrorMessage
  293. WScript.Echo L_SeeHelp_Message
  294. WScript.Quit(ERR_GENERAL_FAILURE)
  295. End If
  296. intOperation = OPER_PAUSE
  297. If oScriptHelper.IsHelpRequested(arg) Then
  298. DisplayPauseHelpMessage
  299. WScript.Quit(ERR_OK)
  300. End If
  301. aArgs = oScriptHelper.GetSwitch(arg)
  302. If UBound(aArgs) = -1 Then
  303. WScript.Echo L_NotEnoughParams_ErrorMessage
  304. WScript.Echo L_SeePauseHelp_Message
  305. WScript.Quit(ERR_GENERAL_FAILURE)
  306. End If
  307. Case "create"
  308. If (intOperation <> 0) Then
  309. WScript.Echo L_OnlyOneOper_ErrorMessage
  310. WScript.Echo L_SeeHelp_Message
  311. WScript.Quit(ERR_GENERAL_FAILURE)
  312. End If
  313. intOperation = OPER_CREATE
  314. If oScriptHelper.IsHelpRequested(arg) Then
  315. DisplayCreateHelpMessage
  316. WScript.Quit(ERR_OK)
  317. End If
  318. strRoot = oScriptHelper.GetSwitch(arg)
  319. aArgs = oScriptHelper.NamedArguments
  320. If strRoot = "" Or UBound(aArgs) = -1 Then
  321. WScript.Echo L_NotEnoughParams_ErrorMessage
  322. WScript.Echo L_SeeCreateHelp_Message
  323. WScript.Quit(ERR_GENERAL_FAILURE)
  324. End If
  325. strName = aArgs(0)
  326. strPort = oScriptHelper.GetSwitch("port")
  327. strIP = oScriptHelper.GetSwitch("ip")
  328. If oScriptHelper.Switches.Exists("dontstart") Then
  329. bDontStart = True
  330. End If
  331. Case "delete"
  332. If (intOperation <> 0) Then
  333. WScript.Echo L_OnlyOneOper_ErrorMessage
  334. WScript.Echo L_SeeHelp_Message
  335. WScript.Quit(ERR_GENERAL_FAILURE)
  336. End If
  337. intOperation = OPER_DELETE
  338. If oScriptHelper.IsHelpRequested(arg) Then
  339. DisplayDeleteHelpMessage
  340. WScript.Quit(ERR_OK)
  341. End If
  342. aArgs = oScriptHelper.GetSwitch(arg)
  343. If UBound(aArgs) = -1 Then
  344. WScript.Echo L_NotEnoughParams_ErrorMessage
  345. WScript.Echo L_SeeDeleteHelp_Message
  346. WScript.Quit(ERR_GENERAL_FAILURE)
  347. End If
  348. Case "query"
  349. If (intOperation <> 0) Then
  350. WScript.Echo L_OnlyOneOper_ErrorMessage
  351. WScript.Echo L_SeeHelp_Message
  352. WScript.Quit(ERR_GENERAL_FAILURE)
  353. End If
  354. intOperation = OPER_QUERY
  355. If oScriptHelper.IsHelpRequested(arg) Then
  356. DisplayQueryHelpMessage
  357. WScript.Quit(ERR_OK)
  358. End If
  359. aArgs = oScriptHelper.GetSwitch(arg)
  360. End Select
  361. Next
  362. ' Check Parameters
  363. If intOperation = 0 Then
  364. WScript.Echo L_OperationRequired_ErrorMessage
  365. WScript.Echo L_SeeHelp_Message
  366. WScript.Quit(ERR_GENERAL_FAILURE)
  367. End If
  368. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  369. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  370. WScript.Echo L_PassWithoutUser_ErrorMessage
  371. WScript.Quit(ERR_GENERAL_FAILURE)
  372. End If
  373. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  374. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  375. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  376. Set oCmdLib.ScriptingHost = WScript.Application
  377. If Err.Number Then
  378. WScript.Echo L_CmdLib_ErrorMessage
  379. WScript.Quit(Err.Number)
  380. Else
  381. strPassword = oCmdLib.GetPassword
  382. Set oCmdLib = Nothing
  383. End If
  384. End If
  385. ' Initializes authentication with remote machine
  386. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  387. If intResult <> 0 Then
  388. WScript.Quit(intResult)
  389. End If
  390. ' Choose operation
  391. Select Case intOperation
  392. Case OPER_START
  393. intResult = ChangeFtpSiteStatus(aArgs, SERVER_STARTED)
  394. Case OPER_STOP
  395. intResult = ChangeFtpSiteStatus(aArgs, SERVER_STOPPED)
  396. Case OPER_PAUSE
  397. intResult = ChangeFtpSiteStatus(aArgs, SERVER_PAUSED)
  398. Case OPER_DELETE
  399. intResult = DeleteFtpSite(aArgs)
  400. Case OPER_CREATE
  401. 'intResult = CreateFtpSite(aArgs)
  402. intResult = CreateFtpSite(strRoot, strName, strPort, strIP, bDontStart)
  403. Case OPER_QUERY
  404. intResult = QueryFtpSite(aArgs)
  405. End Select
  406. ' Return value to command processor
  407. WScript.Quit(intResult)
  408. '''''''''''''''''''''''''
  409. ' End Of Main Block
  410. '''''''''''''''''''''
  411. '''''''''''''''''''''''''''
  412. ' DisplayHelpMessage
  413. '''''''''''''''''''''''''''
  414. Sub DisplayHelpMessage()
  415. WScript.Echo L_Help_HELP_General01_Text
  416. WScript.Echo
  417. WScript.Echo L_Help_HELP_General02_Text
  418. WScript.Echo L_Help_HELP_General03_Text
  419. WScript.Echo
  420. WScript.Echo L_Help_HELP_General04_Text
  421. WScript.Echo L_Help_HELP_General05_Text
  422. WScript.Echo L_Help_HELP_General06_Text
  423. WScript.Echo L_Help_HELP_General07_Text
  424. WScript.Echo L_Help_HELP_General08_Text
  425. WScript.Echo L_Help_HELP_General09_Text
  426. WScript.Echo L_Help_HELP_General10_Text
  427. WScript.Echo L_Help_HELP_General11_Text
  428. WScript.Echo L_Help_HELP_General12_Text
  429. WScript.Echo L_Help_HELP_General13_Text
  430. WScript.Echo L_Help_HELP_General14_Text
  431. WScript.Echo L_Help_HELP_General15_Text
  432. WScript.Echo L_Help_HELP_General18_Text
  433. WScript.Echo L_Help_HELP_General19_Text
  434. WScript.Echo L_Help_HELP_General20_Text
  435. WScript.Echo L_Help_HELP_General21_Text
  436. WScript.Echo
  437. WScript.Echo L_Help_HELP_General22_Text
  438. WScript.Echo
  439. WScript.Echo L_Help_HELP_General23_Text
  440. WScript.Echo L_Help_HELP_General24_Text
  441. WScript.Echo L_Help_HELP_General25_Text
  442. WScript.Echo L_Help_HELP_General27_Text
  443. WScript.Echo L_Help_HELP_General28_Text
  444. WScript.Echo L_Help_HELP_General29_Text
  445. End Sub
  446. Sub DisplayStartHelpMessage()
  447. WScript.Echo L_Help_HELP_Start01_Text
  448. WScript.Echo
  449. WScript.Echo L_Help_HELP_Start02_Text
  450. WScript.Echo L_Help_HELP_Start02p1_Text
  451. WScript.Echo
  452. WScript.Echo L_Help_HELP_Status03_Text
  453. WScript.Echo
  454. WScript.Echo L_Help_HELP_General06_Text
  455. WScript.Echo L_Help_HELP_General07_Text
  456. WScript.Echo L_Help_HELP_General08_Text
  457. WScript.Echo L_Help_HELP_General09_Text
  458. WScript.Echo L_Help_HELP_General10_Text
  459. WScript.Echo L_Help_HELP_Status09_Text
  460. WScript.Echo L_Help_HELP_Status09p1_Text
  461. WScript.Echo
  462. WScript.Echo
  463. WScript.Echo L_Help_HELP_Status10_Text
  464. WScript.Echo
  465. WScript.Echo L_Help_HELP_Start11_Text
  466. WScript.Echo L_Help_HELP_Start12_Text
  467. WScript.Echo L_Help_HELP_Start13_Text
  468. WScript.Echo L_Help_HELP_Start14_Text
  469. End Sub
  470. Sub DisplayStopHelpMessage()
  471. WScript.Echo L_Help_HELP_Stop01_Text
  472. WScript.Echo
  473. WScript.Echo L_Help_HELP_Stop02_Text
  474. WScript.Echo L_Help_HELP_Stop02p1_Text
  475. WScript.Echo
  476. WScript.Echo L_Help_HELP_Status03_Text
  477. WScript.Echo
  478. WScript.Echo L_Help_HELP_General06_Text
  479. WScript.Echo L_Help_HELP_General07_Text
  480. WScript.Echo L_Help_HELP_General08_Text
  481. WScript.Echo L_Help_HELP_General09_Text
  482. WScript.Echo L_Help_HELP_General10_Text
  483. WScript.Echo L_Help_HELP_Status09_Text
  484. WScript.Echo L_Help_HELP_Status09p1_Text
  485. WScript.Echo
  486. WScript.Echo
  487. WScript.Echo L_Help_HELP_Status10_Text
  488. WScript.Echo
  489. WScript.Echo L_Help_HELP_Stop11_Text
  490. WScript.Echo L_Help_HELP_Stop12_Text
  491. WScript.Echo L_Help_HELP_Stop13_Text
  492. WScript.Echo L_Help_HELP_Stop14_Text
  493. End Sub
  494. Sub DisplayPauseHelpMessage()
  495. WScript.Echo L_Help_HELP_Pause01_Text
  496. WScript.Echo
  497. WScript.Echo L_Help_HELP_Pause02_Text
  498. WScript.Echo L_Help_HELP_Pause02p1_Text
  499. WScript.Echo
  500. WScript.Echo L_Help_HELP_Status03_Text
  501. WScript.Echo
  502. WScript.Echo L_Help_HELP_General06_Text
  503. WScript.Echo L_Help_HELP_General07_Text
  504. WScript.Echo L_Help_HELP_General08_Text
  505. WScript.Echo L_Help_HELP_General09_Text
  506. WScript.Echo L_Help_HELP_General10_Text
  507. WScript.Echo L_Help_HELP_Status09_Text
  508. WScript.Echo L_Help_HELP_Status09p1_Text
  509. WScript.Echo
  510. WScript.Echo
  511. WScript.Echo L_Help_HELP_Status10_Text
  512. WScript.Echo
  513. WScript.Echo L_Help_HELP_Pause11_Text
  514. WScript.Echo L_Help_HELP_Pause12_Text
  515. WScript.Echo L_Help_HELP_Pause13_Text
  516. WScript.Echo L_Help_HELP_Pause14_Text
  517. End Sub
  518. Sub DisplayDeleteHelpMessage()
  519. WScript.Echo L_Help_HELP_Delete01_Text
  520. WScript.Echo L_Help_HELP_Delete01p1_Text
  521. WScript.Echo
  522. WScript.Echo L_Help_HELP_Delete02_Text
  523. WScript.Echo L_Help_HELP_Delete02p1_Text
  524. WScript.Echo
  525. WScript.Echo L_Help_HELP_Status03_Text
  526. WScript.Echo
  527. WScript.Echo L_Help_HELP_General06_Text
  528. WScript.Echo L_Help_HELP_General07_Text
  529. WScript.Echo L_Help_HELP_General08_Text
  530. WScript.Echo L_Help_HELP_General09_Text
  531. WScript.Echo L_Help_HELP_General10_Text
  532. WScript.Echo L_Help_HELP_Status09_Text
  533. WScript.Echo L_Help_HELP_Status09p1_Text
  534. WScript.Echo
  535. WScript.Echo
  536. WScript.Echo L_Help_HELP_Status10_Text
  537. WScript.Echo
  538. WScript.Echo L_Help_HELP_Delete11_Text
  539. WScript.Echo L_Help_HELP_Delete12_Text
  540. WScript.Echo L_Help_HELP_Delete13_Text
  541. WScript.Echo L_Help_HELP_Delete14_Text
  542. End Sub
  543. Sub DisplayCreateHelpMessage()
  544. WScript.Echo L_Help_HELP_Create01_Text
  545. WScript.Echo
  546. WScript.Echo L_Help_HELP_Create02_Text
  547. WScript.Echo L_Help_HELP_Create02p1_Text
  548. WScript.Echo
  549. WScript.Echo L_Help_HELP_Status03_Text
  550. WScript.Echo
  551. WScript.Echo L_Help_HELP_General06_Text
  552. WScript.Echo L_Help_HELP_General07_Text
  553. WScript.Echo L_Help_HELP_General08_Text
  554. WScript.Echo L_Help_HELP_General09_Text
  555. WScript.Echo L_Help_HELP_General10_Text
  556. WScript.Echo L_Help_HELP_Create09_Text
  557. WScript.Echo L_Help_HELP_Create09p1_Text
  558. WScript.Echo L_Help_HELP_Create10_Text
  559. WScript.Echo L_Help_HELP_Create10p1_Text
  560. WScript.Echo L_Help_HELP_Create12_Text
  561. WScript.Echo L_Help_HELP_Create12p1_Text
  562. WScript.Echo L_Help_HELP_Create13_Text
  563. WScript.Echo L_Help_HELP_Create13p1_Text
  564. WScript.Echo L_Help_HELP_Create15_Text
  565. WScript.Echo
  566. WScript.Echo L_Help_HELP_Status10_Text
  567. WScript.Echo
  568. WScript.Echo L_Help_HELP_Create22_Text
  569. WScript.Echo L_Help_HELP_Create23_Text
  570. WScript.Echo L_Help_HELP_Create23p1_Text
  571. WScript.Echo L_Help_HELP_Create24_Text
  572. End Sub
  573. Sub DisplayQueryHelpMessage()
  574. WScript.Echo L_Help_HELP_Query01_Text
  575. WScript.Echo
  576. WScript.Echo L_Help_HELP_Query02_Text
  577. WScript.Echo L_Help_HELP_Query02p1_Text
  578. WScript.Echo
  579. WScript.Echo L_Help_HELP_Status03_Text
  580. WScript.Echo
  581. WScript.Echo L_Help_HELP_General06_Text
  582. WScript.Echo L_Help_HELP_General07_Text
  583. WScript.Echo L_Help_HELP_General08_Text
  584. WScript.Echo L_Help_HELP_General09_Text
  585. WScript.Echo L_Help_HELP_General10_Text
  586. WScript.Echo L_Help_HELP_Status09_Text
  587. WScript.Echo L_Help_HELP_Status09p1_Text
  588. WScript.Echo
  589. WScript.Echo
  590. WScript.Echo L_Help_HELP_Status10_Text
  591. WScript.Echo
  592. WScript.Echo L_Help_HELP_Query11_Text
  593. WScript.Echo L_Help_HELP_Query12_Text
  594. WScript.Echo L_Help_HELP_Query13_Text
  595. WScript.Echo L_Help_HELP_Query14_Text
  596. WScript.Echo L_Help_HELP_Query15_Text
  597. End Sub
  598. '''''''''''''''''''''''''''
  599. ' ChangeFtpSiteStatus
  600. '
  601. ' Try to change the status of a site
  602. ' to the one specified
  603. '''''''''''''''''''''''''''
  604. Function ChangeFtpSiteStatus(aArgs, newStatus)
  605. Dim Server, strSiteName
  606. Dim intResult, i, intNewStatus
  607. Dim aSites
  608. Dim providerObj
  609. On Error Resume Next
  610. oScriptHelper.WMIConnect
  611. If Err.Number Then
  612. WScript.Echo L_WMIConnect_ErrorMessage
  613. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  614. ChangeFtpSiteStatus = Err.Number
  615. Exit Function
  616. End If
  617. Set providerObj = oScriptHelper.ProviderObj
  618. intResult = 0
  619. aSites = oScriptHelper.FindSite("Ftp", aArgs)
  620. If IsArray(aSites) Then
  621. If UBound(aSites) = -1 Then
  622. WScript.Echo L_SitesNotFound_ErrorMessage
  623. intResult = ERR_GENERAL_FAILURE
  624. End If
  625. Else
  626. ' Got duplicate sites. We should quit.
  627. ChangeFtpSiteStatus = intResult
  628. Exit Function
  629. End If
  630. For i = LBound(aSites) to UBound(aSites)
  631. strSiteName = aSites(i)
  632. ' Grab site state before trying to start it
  633. Set Server = providerObj.Get("IIsFtpServer='" & strSiteName & "'")
  634. If (Err.Number <> 0) Then
  635. WScript.Echo L_GetFtpServer_ErrorMessage
  636. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  637. intResult = Err.Number
  638. End If
  639. If (Server.ServerState = newStatus) Then
  640. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_IsAlready_Message & " " & _
  641. UCase(SiteStatus(newStatus))
  642. Else
  643. If (Server.ServerState = SERVER_STARTING or Server.ServerState = SERVER_STOPPING or _
  644. Server.ServerState = SERVER_PAUSING or Server.ServerState = SERVER_CONTINUING) Then
  645. WScript.Echo L_CannotControl_ErrorMessage
  646. intResult = ERR_GENERAL_FAILURE
  647. Else
  648. Select Case newStatus
  649. Case SERVER_STARTED
  650. If (Server.ServerState = SERVER_STOPPED) Then
  651. intNewStatus = SERVER_STARTED
  652. Server.Start
  653. Else
  654. If (Server.ServerState = SERVER_PAUSED) Then
  655. intNewStatus = SERVER_CONTINUING
  656. Server.Continue
  657. Else
  658. WScript.Echo strSiteName & ": " & L_CannotStart_Message & _
  659. "(" & L_ServerIs_Message & " " & SiteStatus(Server.ServerState) & ")"
  660. End If
  661. End If
  662. Case SERVER_STOPPED
  663. If (Server.ServerState = SERVER_STARTED) Then
  664. intNewStatus = SERVER_STOPPED
  665. Server.Stop
  666. Else
  667. WScript.Echo L_CannotStop_Message & " (" & L_ServerIs_Message & " " & _
  668. SiteStatus(Server.ServerState) & ")"
  669. End If
  670. Case SERVER_PAUSED
  671. If (Server.ServerState = SERVER_STARTED) Then
  672. intNewStatus = SERVER_PAUSED
  673. Server.Pause
  674. Else
  675. WScript.Echo L_CannotPause_Message & " (" & L_ServerIs_Message & " " & _
  676. SiteStatus(Server.ServerState) & ")"
  677. End If
  678. Case Else
  679. WScript.Echo "!!! BUG BUG: unexpected state"
  680. End Select
  681. ' Error checking
  682. If (Err.Number <> 0) Then
  683. WScript.Echo L_FailChange_ErrorMessage & " " & strSite
  684. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  685. intResult = Err.Number
  686. Else
  687. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_HasBeen_Message & " " & _
  688. UCase(SiteStatus(intNewStatus))
  689. End If
  690. End If
  691. End If
  692. Next
  693. Set Server = Nothing
  694. ChangeFtpSiteStatus = intResult
  695. End Function
  696. '''''''''''''''''''''''''''
  697. ' DeleteFtpSite
  698. '''''''''''''''''''''''''''
  699. Function DeleteFtpSite(aArgs)
  700. Dim strSiteName
  701. Dim RootVDirObj, FtpServerObj
  702. Dim aSites
  703. Dim providerObj
  704. On Error Resume Next
  705. oScriptHelper.WMIConnect
  706. If Err.Number Then
  707. WScript.Echo L_WMIConnect_ErrorMessage
  708. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  709. DeleteFtpSite = Err.Number
  710. Exit Function
  711. End If
  712. Set providerObj = oScriptHelper.ProviderObj
  713. aSites = oScriptHelper.FindSite("Ftp", aArgs)
  714. If IsArray(aSites) Then
  715. If UBound(aSites) = -1 Then
  716. WScript.Echo L_SitesNotFound_ErrorMessage
  717. intResult = ERR_GENERAL_FAILURE
  718. End If
  719. Else
  720. ' Got duplicate sites. We should quit.
  721. ChangeFtpSiteStatus = intResult
  722. Exit Function
  723. End If
  724. For Each strSiteName in aSites
  725. ' Stop and delete the ftp site
  726. Set FtpServerObj = providerObj.Get("IIsFtpServer='" & strSiteName & "'")
  727. If (Err.Number <> 0) Then
  728. WScript.Echo L_SiteGet_ErrorMessage & " " & strSiteName
  729. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  730. DeleteFtpSite = Err.Number
  731. Exit Function
  732. End If
  733. FtpServerObj.Stop
  734. If (Err.Number <> 0) Then
  735. WScript.Echo L_Stop_ErrorMessage & " " & strSiteName
  736. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  737. DeleteFtpSite = Err.Number
  738. Exit Function
  739. End If
  740. FtpServerObj.Delete_
  741. If (Err.Number <> 0) Then
  742. WScript.Echo L_SiteDel_ErrorMessage & " " & strSiteName
  743. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  744. DeleteFtpSite = Err.Number
  745. Exit Function
  746. End If
  747. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_HasBeen_Message & " " & UCase(SiteStatus(8)) & "."
  748. Next
  749. DeleteFtpSite = ERR_OK
  750. End Function
  751. '''''''''''''''''''''''''''
  752. ' CreateFtpSite
  753. '''''''''''''''''''''''''''
  754. Function CreateFtpSite(strRoot, strName, strPort, strIP, bDontStart)
  755. Dim strSitePath
  756. Dim strSiteObjPath
  757. Dim Bindings
  758. Dim objPath, serviceObj
  759. Dim serverObj, vdirObj
  760. Dim strStatus
  761. Dim providerObj
  762. On Error Resume Next
  763. ' Default port
  764. If (strPort = "") Then strPort = "21"
  765. ' Verify port number
  766. If Not oScriptHelper.IsValidPortNumber(strPort) Then
  767. WScript.Echo L_InvalidPort_ErrorMessage
  768. CreateFtpSite = ERR_GENERAL_FAILURE
  769. Exit Function
  770. End If
  771. ' Verify IP Address
  772. If strIP <> "" Then
  773. If Not oScriptHelper.IsValidIPAddress(strIP) Then
  774. WScript.Echo L_InvalidIP_ErrorMessage
  775. CreateFtpSite = ERR_GENERAL_FAILURE
  776. Exit Function
  777. End If
  778. End If
  779. ' Create physical directory
  780. oScriptHelper.CreateFSDir strRoot
  781. If Err.Number Then
  782. Select Case Err.Number
  783. Case &H8007000C
  784. WScript.Echo L_DirFormat_ErrorMessage
  785. WScript.Echo L_SeeCreateHelp_Message
  786. CreateFtpSite = Err.Number
  787. Exit Function
  788. Case &H8007000F
  789. WScript.Echo L_MapDrive_ErrorMessage
  790. CreateFtpSite = Err.Number
  791. Exit Function
  792. Case Else
  793. WScript.Echo L_CannotCreateDir_ErrorMessage
  794. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  795. CreateFtpSite = Err.Number
  796. Exit Function
  797. End Select
  798. End If
  799. ' Time to connect to the IIS namespace
  800. oScriptHelper.WMIConnect
  801. If Err.Number Then
  802. WScript.Echo L_WMIConnect_ErrorMessage
  803. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  804. CreateFtpSite = Err.Number
  805. Exit Function
  806. End If
  807. Set providerObj = oScriptHelper.ProviderObj
  808. ' Build binding object
  809. Bindings = Array(0)
  810. Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
  811. Bindings(0).IP = strIP
  812. Bindings(0).Port = strPort
  813. Set serviceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  814. strSiteObjPath = serviceObj.CreateNewSite(strName, Bindings, strRoot)
  815. If Err Then
  816. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  817. CreateWebSite = Err.Number
  818. Exit Function
  819. End If
  820. ' Parse site ID out of WMI object path
  821. Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
  822. objPath.Path = strSiteObjPath
  823. strSitePath = objPath.Keys.Item("")
  824. ' Set ftp virtual directory properties
  825. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strSitePath & "/ROOT'")
  826. vdirObj.AccessFlags = 1 ' read
  827. vdirObj.Put_()
  828. If Err Then
  829. WScript.Echo L_VDirPut_ErrorMessage
  830. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  831. providerObj.Delete(strSiteObjPath)
  832. CreateWebSite = Err.Number
  833. Exit Function
  834. End If
  835. ' Sometimes, the site is started right after its creation. Let's stop it at this point.
  836. Set serverObj = providerObj.Get("IIsFtpServer='" & strSitePath & "'")
  837. serverObj.Stop
  838. ' Should we start the site?
  839. If Not bDontStart Then
  840. serverObj.Start
  841. ' If we cannot start the server, check for error stating the port is already in use
  842. If Err.Number = &H80070034 Or Err.Number = &H80070020 Or Err.Number = &H80070057 Then
  843. strStatus = UCase(SiteStatus(4)) & " " & L_BindingConflict_ErrorMessage
  844. Else
  845. strStatus = UCase(SiteStatus(2))
  846. End If
  847. Else
  848. strStatus = UCase(SiteStatus(4))
  849. End If
  850. If (strServer = ".") Then
  851. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  852. End If
  853. If (strIP = "") Then strIP = L_AllUnassigned_Text
  854. ' Post summary
  855. WScript.Echo L_Server_Text & Space(14 - Len(L_Server_Text)) & "= " & UCase(strServer)
  856. WScript.Echo L_SiteName_Text & Space(14 - Len(L_SiteName_Text)) & "= " & strName
  857. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strSitePath
  858. WScript.Echo L_IP_Text & Space(14 - Len(L_IP_Text)) & "= " & strIP
  859. WScript.Echo L_Port_Text & Space(14 - Len(L_Port_Text)) & "= " & strPort
  860. WScript.Echo L_Root_Text & Space(14 - Len(L_Root_Text)) & "= " & strRoot
  861. WScript.Echo L_Status_Text& Space(14 - Len(L_Status_Text)) & "= " & strStatus
  862. CreateFtpSite = intResult
  863. End Function
  864. '''''''''''''''''''''''''''
  865. ' QueryFtpSite
  866. '''''''''''''''''''''''''''
  867. Function QueryFtpSite(aArgs)
  868. Dim Servers, Server, strQuery
  869. Dim ServerObj
  870. Dim i, intResult
  871. Dim bindings, binding
  872. Dim line, strIP, strPort, strState
  873. Dim providerObj
  874. Dim bFirstIteration
  875. On Error Resume Next
  876. oScriptHelper.WMIConnect
  877. If Err.Number Then
  878. WScript.Echo L_WMIConnect_ErrorMessage
  879. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  880. QueryFtpSiteStatus = Err.Number
  881. Exit Function
  882. End If
  883. Set providerObj = oScriptHelper.ProviderObj
  884. intResult = 0
  885. If (UBound(aArgs) = -1) Then
  886. strQuery = "select Name, ServerComment, ServerBindings from IIsFtpServerSetting"
  887. Else
  888. strQuery = "select Name, ServerComment, ServerBindings from IIsFtpServerSetting where "
  889. For i = LBound(aArgs) to UBound(aArgs)
  890. strQuery = strQuery & "(Name='" & aArgs(i) & "' or ServerComment='" & aArgs(i) & "')"
  891. If (i <> UBound(aArgs)) Then
  892. strQuery = strQuery & " or "
  893. End If
  894. Next
  895. End If
  896. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  897. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  898. If (Err.Number <> 0) Then
  899. WScript.Echo L_Query_ErrorMessage
  900. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  901. WScript.Quit(Err.Number)
  902. End If
  903. bFirstIteration = True
  904. For Each Server in Servers
  905. bindings = Server.ServerBindings
  906. If bFirstIteration Then
  907. WScript.Echo L_SiteName_Text & " (" & L_MetabasePath_Message & ")" & _
  908. Space(30 - Len(L_SiteName_Text & L_MetabasePath_Message) + 3) & _
  909. L_Status_Text & Space(4) & L_IP_Text & Space(14) & L_Port_Text
  910. WScript.Echo "=============================================================================="
  911. End If
  912. ' Get server status from the element instance
  913. Set ServerObj = providerObj.Get("IIsFtpServer='" & Server.Name & "'")
  914. strState = UCase(SiteStatus(ServerObj.ServerState))
  915. If (IsArray(bindings)) Then
  916. For i = LBound(bindings) to UBound(bindings)
  917. If (bindings(i).IP = "") Then
  918. strIP = L_All_Text
  919. Else
  920. strIP = bindings(i)
  921. End If
  922. strPort = bindings(i).Port
  923. ' If this is the first binding list, print server comment and server name
  924. If (i = LBound(bindings)) Then
  925. line = Server.ServerComment & " (" & Server.Name & ")" & _
  926. Space(30 - Len(Server.ServerComment & Server.Name) + 3) & strState & _
  927. Space(10 - Len(strState)) & strIP & Space(16 - Len(strIP)) & strPort
  928. Else
  929. line = Space(44) & strIP & Space(16 - Len(strIP)) & strPort
  930. End If
  931. WScript.Echo line
  932. Next
  933. End If
  934. bFirstIteration = False
  935. Next
  936. If bFirstIteration Then
  937. WScript.Echo L_SitesNotFound_ErrorMessage
  938. End If
  939. End Function