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.

782 lines
28 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsFtpDr.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_FtpDir_Message = "Ftp directory"
  16. Const L_HasBeenDeleted_Message = "has been DELETED"
  17. Const L_InvalidPath_ErrorMessage = "Invalid site path."
  18. Const L_VPath_Message = "Virtual Path"
  19. Const L_Root_Message = "ROOT"
  20. Const L_MetabasePath_Message = "Metabase Path"
  21. Const L_AliasName_Text = "Alias"
  22. Const L_Path_Text = "Physical Root"
  23. Const L_Error_ErrorMessage = "Error"
  24. Const L_VDirDel_ErrorMessage = "Could not delete ftp directory."
  25. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory."
  26. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the '<drive>:\<path>' format."
  27. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  28. Const L_NotEnoughParam_ErrorMessage = "Not enough parameters."
  29. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  30. Const L_VDirExists1_ErrorMessage = "Virtual directory"
  31. Const L_VDirExists2_ErrorMessage = "already exists."
  32. Const L_VDirDoesntExist_ErrorMessage = "Virtual directory doesn't exist"
  33. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  34. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  35. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  36. Const L_CmdLib_ErrorMessage = "Unable to create instance of the CmdLib object."
  37. Const L_VDirsNotFound_ErrorMessage = "No virtual sub-directories available."
  38. Const L_SiteNotFound_ErrorMessage = "Could not find ftpsite"
  39. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  40. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  41. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  42. Const L_GetSetting_ErrorMessage = "Unable to get Setting class from IIS namespace."
  43. Const L_CannotDelRoot_ErrorMessage = "Cannot delete the ROOT virtual directory. Please specify another one."
  44. Const L_WrongVDirPath_ErrorMessage = "Parent virtual directory points to an unexistant file system path."
  45. Const L_CannotBuildNameSpace_ErrorMessage = "Could not build metabase namespace for the new virtual directory."
  46. Const L_KeyIsntVDir_ErrorMessage = "Specified metabase path is not a virtual directory."
  47. Const L_CannotGetVDir_ErrorMessage = "Could not get virtual directory object."
  48. Const L_InvalidAlias_ErrorMessage = "Alias contains invalid character(s)."
  49. Const L_CannotGetParentVDir_ErrorMessage = "Error getting parent virtual directory."
  50. Const L_ParentVDirNotPresent_ErrorMessage = "Parent virtual directory doesn't exist."
  51. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  52. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: "
  53. '''''''''''''''''''''
  54. ' Help
  55. ' General help messages
  56. Const L_SeeHelp_Message = "Type IIsFtpDr /? for help."
  57. Const L_SeeCreateHelp_Message = "Type IIsFtpDr /create /? for help."
  58. Const L_SeeDeleteHelp_Message = "Type IIsFtpDr /delete /? for help."
  59. Const L_SeeQueryHelp_Message = "Type IIsFtpDr /query /? for help."
  60. Const L_Help_HELP_General01_Text = "Description: Create, delete, or query a ftp directory"
  61. Const L_Help_HELP_General02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /<operation>"
  62. Const L_Help_HELP_General03_Text = " [arguments]"
  63. Const L_Help_HELP_General04_Text = "Parameters:"
  64. Const L_Help_HELP_General06_Text = "Value Description"
  65. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  66. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  67. Const L_Help_HELP_General09_Text = " [Default: current user]"
  68. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  69. Const L_Help_HELP_General11_Text = "<operation> /create Creates a ftp virtual directory on a"
  70. Const L_Help_HELP_General12_Text = " specified ftp site."
  71. Const L_Help_HELP_General13_Text = " /delete Deletes a ftp virtual directory from a"
  72. Const L_Help_HELP_General14_Text = " specified ftp site."
  73. Const L_Help_HELP_General15_Text = " /query Lists all virtual directories under"
  74. Const L_Help_HELP_General16_Text = " the specified path."
  75. Const L_Help_HELP_General17_Text = "For detailed usage:"
  76. Const L_Help_HELP_General18_Text = "IIsFtpDr /create /?"
  77. Const L_Help_HELP_General19_Text = "IIsFtpDr /delete /?"
  78. Const L_Help_HELP_General20_Text = "IIsFtpDr /query /?"
  79. ' Common to all status change commands
  80. Const L_Help_HELP_Common03_Text = "Parameters:"
  81. Const L_Help_HELP_Common09_Text = "<ftpsite> Use either the site name or metabase path to specify"
  82. Const L_Help_HELP_Common09p1_Text = " the site. (""Default Ftp Site"" or msftpsvc/1)"
  83. Const L_Help_HELP_Common10_Text = "<path> Virtual path for the new virtual directory's parent."
  84. Const L_Help_HELP_Common10p1_Text = " This virtual path must already exist."
  85. Const L_Help_HELP_Common11_Text = "Examples:"
  86. ' Delete help messages
  87. Const L_Help_HELP_Delete01_Text = "Description: Deletes a ftp virtual directory from a specified ftp site."
  88. Const L_Help_HELP_Delete02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /delete"
  89. Const L_Help_HELP_Delete02p1_Text = " <ftpsite>[/path]<alias>"
  90. Const L_Help_HELP_Delete11_Text = "IIsFtpDr /delete ""My Site""/Mydir"
  91. Const L_Help_HELP_Delete12_Text = "IIsFtpDr /delete msftpsvc/1/ROOT/Users/Public/Mydir"
  92. Const L_Help_HELP_Delete13_Text = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /delete ""My Site""/Mydir"
  93. ' Query help messages
  94. Const L_Help_HELP_Query01_Text = "Description: Lists all virtual directories under a given path."
  95. Const L_Help_HELP_Query02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /query"
  96. Const L_Help_HELP_Query02p1_Text = " <ftpsite>[/path]"
  97. Const L_Help_HELP_Query11_Text = "IIsFtpDr /query ""My Site"""
  98. Const L_Help_HELP_Query12_Text = "IIsFtpDr /query msftpsvc/1/ROOT"
  99. Const L_Help_HELP_Query13_Text = "IIsFtpDr /query ""My Site""/Users/Public"
  100. Const L_Help_HELP_Query14_Text = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /query ""My Site""/Users"
  101. ' Create help messages
  102. Const L_Help_HELP_Create01_Text = "Description: Creates a ftp virtual directory on a specified ftp site."
  103. Const L_Help_HELP_Create02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /create"
  104. Const L_Help_HELP_Create02p1_Text = " <ftpsite>[/path] <alias> <root>"
  105. Const L_Help_HELP_Create11_Text = "<alias> The name of the virtual directory"
  106. Const L_Help_HELP_Create12_Text = "<root> Physical path of the virtual directory. If the"
  107. Const L_Help_HELP_Create12p1_Text = " physical path does not exist, it will be created."
  108. Const L_Help_HELP_Create15_Text = "IIsFtpDr /create ""My Site"" Mydir c:\mydir"
  109. Const L_Help_HELP_Create16_Text = "IIsFtpDr /create msftpsvc/1/ROOT MyDir c:\mydir"
  110. Const L_Help_HELP_Create17_Text = "IIsFtpDr /create ""My Site""/Users/Public Mydir c:\mydir"
  111. Const L_Help_HELP_Create18_Text = "IIsFtpDr /s Server1 /u Administrator /p p@assWOrd /create ""My Site"" Mydir"
  112. Const L_Help_HELP_Create19_Text = " c:\mydir"
  113. ''''''''''''''''''''''''
  114. ' Operation codes
  115. Const OPER_DELETE = 1
  116. Const OPER_CREATE = 2
  117. Const OPER_QUERY = 3
  118. '
  119. ' Main block
  120. '
  121. Dim oScriptHelper, oCmdLib
  122. Dim strServer, strUser, strPassword, strSite
  123. Dim strPath, strVPath, strAlias, strRoot
  124. Dim intOperation, intResult
  125. Dim aArgs, arg
  126. Dim strCmdLineOptions
  127. Dim oError
  128. ' Default values
  129. strServer = "."
  130. strUser = ""
  131. strPassword = ""
  132. intOperation = 0
  133. strSite = ""
  134. strPath = ""
  135. ' Instantiate script helper object
  136. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  137. If Err.Number <> 0 Then
  138. WScript.Echo L_ScriptHelper_ErrorMessage
  139. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  140. WScript.Quit(ERR_GENERAL_FAILURE)
  141. End If
  142. Set oScriptHelper.ScriptHost = WScript
  143. ' Check if we are being run with cscript.exe instead of wscript.exe
  144. oScriptHelper.CheckScriptEngine
  145. ' Minimum number of parameters must exist
  146. If WScript.Arguments.Count < 1 Then
  147. WScript.Echo L_NotEnoughParam_ErrorMessage
  148. WScript.Echo L_SeeHelp_Message
  149. WScript.Quit(ERR_GENERAL_FAILURE)
  150. End If
  151. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];delete:d:1;create:c:3;query:q:1"
  152. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  153. If Not oError Is Nothing Then
  154. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  155. ' Not enough arguments for a specified switch
  156. WScript.Echo L_NotEnoughParams_ErrorMessage
  157. Select Case LCase(oError.SwitchName)
  158. Case "create"
  159. WScript.Echo L_SeeCreateHelp_Message
  160. Case "delete"
  161. WScript.Echo L_SeeDeleteHelp_Message
  162. Case "query"
  163. WScript.Echo L_SeeQueryHelp_Message
  164. Case Else
  165. WScript.Echo L_SeeHelp_Message
  166. End Select
  167. Else
  168. ' Invalid switch
  169. WScript.Echo L_InvalidSwitch_ErrorMessage & oError.SwitchName
  170. WScript.Echo L_SeeHelp_Message
  171. End If
  172. WScript.Quit(ERR_GENERAL_FAILURE)
  173. End If
  174. If oScriptHelper.GlobalHelpRequested Then
  175. DisplayHelpMessage
  176. WScript.Quit(ERR_OK)
  177. End If
  178. For Each arg In oScriptHelper.Switches
  179. Select Case arg
  180. Case "server"
  181. ' Server information
  182. strServer = oScriptHelper.GetSwitch(arg)
  183. Case "user"
  184. ' User information
  185. strUser = oScriptHelper.GetSwitch(arg)
  186. Case "password"
  187. ' Password information
  188. strPassword = oScriptHelper.GetSwitch(arg)
  189. Case "create"
  190. If (intOperation <> 0) Then
  191. WScript.Echo L_OnlyOneOper_ErrorMessage
  192. WScript.Echo L_SeeHelp_Message
  193. WScript.Quit(ERR_GENERAL_FAILURE)
  194. End If
  195. intOperation = OPER_CREATE
  196. If oScriptHelper.IsHelpRequested(arg) Then
  197. DisplayCreateHelpMessage
  198. WScript.Quit(ERR_OK)
  199. End If
  200. aArgs = oScriptHelper.GetSwitch(arg)
  201. strVPath = aArgs(0)
  202. strAlias = aArgs(1)
  203. strRoot = aArgs(2)
  204. Case "delete"
  205. If (intOperation <> 0) Then
  206. WScript.Echo L_OnlyOneOper_ErrorMessage
  207. WScript.Echo L_SeeHelp_Message
  208. WScript.Quit(ERR_GENERAL_FAILURE)
  209. End If
  210. intOperation = OPER_DELETE
  211. If oScriptHelper.IsHelpRequested(arg) Then
  212. DisplayDeleteHelpMessage
  213. WScript.Quit(ERR_OK)
  214. End If
  215. strPath = oScriptHelper.GetSwitch(arg)
  216. Case "query"
  217. If (intOperation <> 0) Then
  218. WScript.Echo L_OnlyOneOper_ErrorMessage
  219. WScript.Echo L_SeeHelp_Message
  220. WScript.Quit(ERR_GENERAL_FAILURE)
  221. End If
  222. intOperation = OPER_QUERY
  223. If oScriptHelper.IsHelpRequested(arg) Then
  224. DisplayQueryHelpMessage
  225. WScript.Quit(ERR_OK)
  226. End If
  227. strPath = oScriptHelper.GetSwitch(arg)
  228. ' strVPath = aArgs(0)
  229. ' strAlias = aArgs(1)
  230. ' strRoot = aArgs(2)
  231. End Select
  232. Next
  233. ' Check Parameters
  234. If (intOperation = 0) Then
  235. WScript.Echo L_OperationRequired_ErrorMessage
  236. WScript.Echo L_SeeHelp_Message
  237. WScript.Quit(ERR_GENERAL_FAILURE)
  238. End If
  239. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  240. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  241. WScript.Echo L_PassWithoutUser_ErrorMessage
  242. WScript.Quit(ERR_GENERAL_FAILURE)
  243. End If
  244. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  245. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  246. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  247. Set oCmdLib.ScriptingHost = WScript.Application
  248. If Err.Number Then
  249. WScript.Echo L_CmdLib_ErrorMessage
  250. WScript.Quit(Err.Number)
  251. Else
  252. strPassword = oCmdLib.GetPassword
  253. Set oCmdLib = Nothing
  254. End If
  255. End If
  256. ' Initializes authentication with remote machine
  257. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  258. If intResult <> 0 Then
  259. WScript.Quit(intResult)
  260. End If
  261. ' Choose operation
  262. Select Case intOperation
  263. Case OPER_CREATE
  264. intResult = CreateFtpVDir(strVPath, strAlias, strRoot)
  265. Case OPER_DELETE
  266. intResult = DeleteFtpVDir(strPath)
  267. Case OPER_QUERY
  268. intResult = QueryFtpVDir(strPath)
  269. End Select
  270. ' Return value to command processor
  271. WScript.Quit(intResult)
  272. '''''''''''''''''''''''''
  273. ' End Of Main Block
  274. '''''''''''''''''''''
  275. '''''''''''''''''''''''''''
  276. ' ParseSitePath
  277. '''''''''''''''''''''''''''
  278. Function ParseSitePath(strSitePath)
  279. Dim iFirstSlash, iSecondSlash, iIndex
  280. Dim strSite, strPath
  281. Dim aPath, aFtpSites
  282. On Error Resume Next
  283. ' Replace any existing back-slashes with forward-slashes
  284. strSitePath = Replace(strSitePath, "\", "/")
  285. aPath = Split(strSitePath, "/", -1)
  286. ' Fills strPath
  287. If (UCase(aPath(0)) = "MSFTPSVC") Then
  288. ' First argument is a metabase path
  289. If (UBound(aPath) < 1) Then
  290. WScript.Echo L_InvalidPath_ErrorMessage
  291. WScript.Quit(ERR_GENERAL_FAILURE)
  292. End If
  293. ' Second array element must be a number (site ID)
  294. If Not IsNumeric(aPath(1)) Then
  295. WScript.Echo L_InvalidPath_ErrorMessage
  296. WScript.Quit(ERR_GENERAL_FAILURE)
  297. End If
  298. ' Second element of aPath should be the site number so ...
  299. strPath = "MSFTPSVC/" & aPath(1)
  300. ' Call FindFtpSite to make sure ftp site exists
  301. aFtpSites = oScriptHelper.FindSite("Ftp", Array(strPath))
  302. If IsArray(aFtpSites) Then
  303. If UBound(aFtpSites) = -1 Then
  304. WScript.Echo L_SiteNotFound_ErrorMessage & " """ & strPath & """."
  305. ParseSitePath = Empty
  306. Exit Function
  307. End If
  308. End If
  309. strPath = strPath & "/ROOT"
  310. ' Check for ROOT string and grab the rest for strPath
  311. iIndex = 1
  312. If (UBound(aPath) > 1) Then
  313. If (UCase(aPath(2)) = "ROOT") Then
  314. iIndex = 2
  315. End If
  316. End If
  317. Else
  318. ' First argument is a site name (server comment property)
  319. ' Call FindFtpSite to resolve site name to metabase path
  320. aFtpSites = oScriptHelper.FindSite("Ftp", Array(aPath(0)))
  321. If IsArray(aFtpSites) Then
  322. If UBound(aFtpSites) = -1 Then
  323. WScript.Echo L_SiteNotFound_ErrorMessage & " """ & aPath(0) & """."
  324. ParseSitePath = Empty
  325. Exit Function
  326. Else
  327. strPath = aFtpSites(0)
  328. End If
  329. Else
  330. ' Got duplicate sites. We should quit.
  331. ParseSitePath = Empty
  332. Exit Function
  333. End If
  334. strPath = strPath & "/ROOT"
  335. iIndex = 0
  336. End If
  337. ' Build strPath
  338. iIndex = iIndex + 1
  339. Do While iIndex <= UBound(aPath)
  340. If (aPath(iIndex) = "") Then
  341. Exit Do
  342. End If
  343. strPath = strPath & "/" & aPath(iIndex)
  344. iIndex = iIndex + 1
  345. Loop
  346. ParseSitePath = strPath
  347. End Function
  348. '''''''''''''''''''''''''''
  349. ' DisplayHelpMessage
  350. '''''''''''''''''''''''''''
  351. Sub DisplayHelpMessage()
  352. WScript.Echo L_Help_HELP_General01_Text
  353. WScript.Echo
  354. WScript.Echo L_Help_HELP_General02_Text
  355. WScript.Echo L_Help_HELP_General03_Text
  356. WScript.Echo
  357. WScript.Echo L_Help_HELP_General04_Text
  358. WScript.Echo
  359. WScript.Echo L_Help_HELP_General06_Text
  360. WScript.Echo L_Help_HELP_General07_Text
  361. WScript.Echo L_Help_HELP_General08_Text
  362. WScript.Echo L_Help_HELP_General09_Text
  363. WScript.Echo L_Help_HELP_General10_Text
  364. WScript.Echo L_Help_HELP_General11_Text
  365. WScript.Echo L_Help_HELP_General12_Text
  366. WScript.Echo L_Help_HELP_General13_Text
  367. WScript.Echo L_Help_HELP_General14_Text
  368. WScript.Echo L_Help_HELP_General15_Text
  369. WScript.Echo L_Help_HELP_General16_Text
  370. WScript.Echo
  371. WScript.Echo L_Help_HELP_General17_Text
  372. WScript.Echo
  373. WScript.Echo L_Help_HELP_General18_Text
  374. WScript.Echo L_Help_HELP_General19_Text
  375. WScript.Echo L_Help_HELP_General20_Text
  376. End Sub
  377. Sub DisplayDeleteHelpMessage()
  378. WScript.Echo L_Help_HELP_Delete01_Text
  379. WScript.Echo
  380. WScript.Echo L_Help_HELP_Delete02_Text
  381. WScript.Echo L_Help_HELP_Delete02p1_Text
  382. WScript.Echo
  383. WScript.Echo L_Help_HELP_Common03_Text
  384. WScript.Echo
  385. WScript.Echo L_Help_HELP_General06_Text
  386. WScript.Echo L_Help_HELP_General07_Text
  387. WScript.Echo L_Help_HELP_General08_Text
  388. WScript.Echo L_Help_HELP_General09_Text
  389. WScript.Echo L_Help_HELP_General10_Text
  390. WScript.Echo L_Help_HELP_Common09_Text
  391. WScript.Echo L_Help_HELP_Common09p1_Text
  392. WScript.Echo L_Help_HELP_Common10_Text
  393. WScript.Echo
  394. WScript.Echo L_Help_HELP_Common11_Text
  395. WScript.Echo
  396. WScript.Echo L_Help_HELP_Delete11_Text
  397. WScript.Echo L_Help_HELP_Delete12_Text
  398. WScript.Echo L_Help_HELP_Delete13_Text
  399. End Sub
  400. Sub DisplayCreateHelpMessage()
  401. WScript.Echo L_Help_HELP_Create01_Text
  402. WScript.Echo
  403. WScript.Echo L_Help_HELP_Create02_Text
  404. WScript.Echo L_Help_HELP_Create02p1_Text
  405. WScript.Echo
  406. WScript.Echo L_Help_HELP_Common03_Text
  407. WScript.Echo
  408. WScript.Echo L_Help_HELP_General06_Text
  409. WScript.Echo L_Help_HELP_General07_Text
  410. WScript.Echo L_Help_HELP_General08_Text
  411. WScript.Echo L_Help_HELP_General09_Text
  412. WScript.Echo L_Help_HELP_General10_Text
  413. WScript.Echo L_Help_HELP_Common09_Text
  414. WScript.Echo L_Help_HELP_Common09p1_Text
  415. WScript.Echo L_Help_HELP_Common10_Text
  416. WScript.Echo L_Help_HELP_Common10p1_Text
  417. WScript.Echo L_Help_HELP_Create11_Text
  418. WScript.Echo L_Help_HELP_Create12_Text
  419. WScript.Echo L_Help_HELP_Create12p1_Text
  420. WScript.Echo
  421. WScript.Echo L_Help_HELP_Common11_Text
  422. WScript.Echo
  423. WScript.Echo L_Help_HELP_Create15_Text
  424. WScript.Echo L_Help_HELP_Create16_Text
  425. WScript.Echo L_Help_HELP_Create17_Text
  426. WScript.Echo L_Help_HELP_Create18_Text
  427. WScript.Echo L_Help_HELP_Create19_Text
  428. End Sub
  429. Sub DisplayQueryHelpMessage()
  430. WScript.Echo L_Help_HELP_Query01_Text
  431. WScript.Echo
  432. WScript.Echo L_Help_HELP_Query02_Text
  433. WScript.Echo L_Help_HELP_Query02p1_Text
  434. WScript.Echo
  435. WScript.Echo L_Help_HELP_Common03_Text
  436. WScript.Echo
  437. WScript.Echo L_Help_HELP_General06_Text
  438. WScript.Echo L_Help_HELP_General07_Text
  439. WScript.Echo L_Help_HELP_General08_Text
  440. WScript.Echo L_Help_HELP_General09_Text
  441. WScript.Echo L_Help_HELP_General10_Text
  442. WScript.Echo L_Help_HELP_Common09_Text
  443. WScript.Echo L_Help_HELP_Common09p1_Text
  444. WScript.Echo L_Help_HELP_Common10_Text
  445. WScript.Echo L_Help_HELP_Common10p1_Text
  446. WScript.Echo
  447. WScript.Echo L_Help_HELP_Common11_Text
  448. WScript.Echo
  449. WScript.Echo L_Help_HELP_Query11_Text
  450. WScript.Echo L_Help_HELP_Query12_Text
  451. WScript.Echo L_Help_HELP_Query13_Text
  452. WScript.Echo L_Help_HELP_Query14_Text
  453. End Sub
  454. '''''''''''''''''''''''''''
  455. ' DeleteFtpVDir
  456. '''''''''''''''''''''''''''
  457. Function DeleteFtpVDir(strVPath)
  458. Dim strPath
  459. Dim rootVDirObj, providerObj
  460. On Error Resume Next
  461. oScriptHelper.WMIConnect
  462. If Err.Number Then
  463. WScript.Echo L_WMIConnect_ErrorMessage
  464. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  465. ChangeFtpSiteStatus = Err.Number
  466. Exit Function
  467. End If
  468. Set providerObj = oScriptHelper.ProviderObj
  469. strPath = ParseSitePath(strVPath)
  470. If IsEmpty(strPath) Then
  471. ' Got problems parsing the path
  472. WScript.Echo L_SeeDeleteHelp_Message
  473. DeleteFtpVDir = ERR_GENERAL_FAILURE
  474. Exit Function
  475. End If
  476. ' Don't delete ROOT Vdir
  477. If UCase(Right(strPath, 4)) = "ROOT" Then
  478. WScript.Echo L_CannotDelRoot_ErrorMessage
  479. DeleteFtpVDir = ERR_GENERAL_FAILURE
  480. Exit Function
  481. End If
  482. ' Check vdir existance
  483. Set rootVDirObj = providerObj.Get("IIsFtpVirtualDir='" & strPath & "'")
  484. If Err.Number Then
  485. Select Case Err.Number
  486. Case &H80041002
  487. WScript.Echo L_VDirDoesntExist_ErrorMessage & " (" & strVPath & ")"
  488. Case &H8004103A
  489. WScript.Echo L_KeyIsntVDir_ErrorMessage
  490. Case Else
  491. WScript.Echo L_CannotGetVDir_ErrorMessage
  492. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  493. End Select
  494. DeleteFtpVDir = Err.Number
  495. Exit Function
  496. End If
  497. rootVDirObj.Delete_()
  498. If Err.Number Then
  499. WScript.Echo L_VDirDel_ErrorMessage
  500. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  501. DeleteFtpVDir = Err.Number
  502. Exit Function
  503. End If
  504. WScript.Echo L_FtpDir_Message & " " & strVPath & " " & L_HasBeenDeleted_Message & "."
  505. DeleteFtpVDir = ERR_OK
  506. End Function
  507. '''''''''''''''''''''''''''
  508. ' CreateFtpVDir
  509. '''''''''''''''''''''''''''
  510. Function CreateFtpVDir(strVPath, strAlias, strRoot)
  511. Dim strPath, strStatus, strNewVdir, strRootVDir
  512. Dim vdirClassObj, serverObj, vdirObj, providerObj
  513. Dim intResult
  514. On Error Resume Next
  515. ' Parse Alias for correctness
  516. If InStr(strAlias, "/") <> 0 Or InStr(strAlias, "\") <> 0 Then
  517. WScript.Echo L_InvalidAlias_ErrorMessage
  518. WScript.Echo L_SeeCreateHelp_Message
  519. CreateWebVDir = ERR_GENERAL_FAILURE
  520. Exit Function
  521. End If
  522. oScriptHelper.WMIConnect
  523. If Err.Number Then
  524. WScript.Echo L_WMIConnect_ErrorMessage
  525. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  526. CreateFtpVDir = Err.Number
  527. Exit Function
  528. End If
  529. Set providerObj = oScriptHelper.ProviderObj
  530. ' Extract options from array to the correspondent variables
  531. strPath = ParseSitePath(strVPath)
  532. If IsEmpty(strPath) Then
  533. ' Got problems parsing the path
  534. WScript.Echo L_SeeCreateHelp_Message
  535. CreateFtpVDir = ERR_GENERAL_FAILURE
  536. Exit Function
  537. End If
  538. ' Build new vdir name
  539. strNewVdir = strPath & "/" & strAlias
  540. ' Check if vdir already exists
  541. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strNewVdir & "'")
  542. If Err.Number = 0 Then
  543. WScript.Echo L_VDirExists1_ErrorMessage & " '" & strNewVdir & "' " & L_VDirExists2_ErrorMessage
  544. CreateFtpVDir = ERR_GENERAL_FAILURE
  545. Exit Function
  546. End If
  547. Err.Clear
  548. ' Check if parent vdir exists
  549. ' We need to do this because FTP doesn't have the concept similar to a WebDirectory
  550. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strPath & "'")
  551. If Err.Number Then
  552. Select Case Err.Number
  553. Case &H80041002
  554. WScript.Echo L_ParentVDirNotPresent_ErrorMessage
  555. Case Else
  556. WScript.Echo L_CannotGetParentVDir_ErrorMessage
  557. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  558. End Select
  559. CreateFtpVDir = Err.Number
  560. Exit Function
  561. End If
  562. ' Create physical directory
  563. oScriptHelper.CreateFSDir strRoot
  564. If Err.Number Then
  565. Select Case Err.Number
  566. Case &H8007000C
  567. WScript.Echo L_DirFormat_ErrorMessage
  568. WScript.Echo L_SeeCreateHelp_Message
  569. Case &H8007000F
  570. WScript.Echo L_MapDrive_ErrorMessage
  571. Case Else
  572. WScript.Echo L_CannotCreateDir_ErrorMessage
  573. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  574. End Select
  575. CreateFtpVDir = Err.Number
  576. Exit Function
  577. End If
  578. ' Remove trailing slash (if present)
  579. If (Right(strRoot, 1) = "\") Then
  580. strRoot = Left(strRoot, Len(strRoot) - 1)
  581. End If
  582. ' Create new ftp virtual directory
  583. Set vdirClassObj = providerObj.Get("IIsFtpVirtualDirSetting")
  584. Set vdirObj = vdirClassObj.SpawnInstance_()
  585. vdirObj.Name = strNewVdir
  586. vdirObj.Path = strRoot
  587. ' Set ftp virtual directory properties
  588. vdirObj.AccessFlags = 1 ' read access
  589. vdirObj.Put_()
  590. ' Remove trailing slash (if present)
  591. If (Right(strVPath, 1) = "/") Then
  592. strVPath = Left(strVPath, Len(strVPath) - 1)
  593. End If
  594. If (strServer = ".") Then
  595. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  596. End If
  597. ' Post summary
  598. WScript.Echo L_Server_Message & Space(14 - Len(L_Server_Message)) & "= " & UCase(strServer)
  599. WScript.Echo L_VPath_Message & Space(14 - Len(L_VPath_Message)) & "= " & strVPath & "/" & strAlias
  600. WScript.Echo L_Root_Message & Space(14 - Len(L_Root_Message)) & "= " & strRoot
  601. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strNewVdir
  602. CreateFtpVDir = intResult
  603. End Function
  604. '''''''''''''''''''''''''''
  605. ' Helper Functions
  606. '''''''''''''''''''''''''''
  607. '''''''''''''''''''''''''''
  608. ' QueryFtpVDir
  609. '''''''''''''''''''''''''''
  610. Function QueryFtpVDir(strVDir)
  611. Dim Servers, Server, strQuery
  612. Dim bFirstIteration
  613. Dim vdirObj, providerObj
  614. Dim strServer, strPath, strVDirName
  615. On Error Resume Next
  616. oScriptHelper.WMIConnect
  617. If Err.Number Then
  618. WScript.Echo L_WMIConnect_ErrorMessage
  619. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  620. QueryFtpVDir = Err.Number
  621. Exit Function
  622. End If
  623. Set providerObj = oScriptHelper.ProviderObj
  624. strPath = ParseSitePath(strVDir)
  625. If IsEmpty(strPath) Then
  626. ' Got problems parsing the path
  627. WScript.Echo L_SeeQueryHelp_Message
  628. QueryFtpVDir = ERR_GENERAL_FAILURE
  629. Exit Function
  630. End If
  631. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  632. strQuery = "ASSOCIATORS OF {IIsFtpVirtualDir=""" & strPath & """} WHERE ResultClass = IIsFtpVirtualDir " & _
  633. "ResultRole = PartComponent"
  634. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  635. If (Err.Number <> 0) Then
  636. WScript.Echo L_Query_ErrorMessage
  637. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  638. QueryFtpVDir = Err.Number
  639. Exit Function
  640. End If
  641. bFirstIteration = True
  642. For Each Server in Servers
  643. If bFirstIteration Then
  644. WScript.Echo L_AliasName_Text & Space(25 - Len(L_AliasName_Text)) & L_Path_Text
  645. WScript.Echo "=============================================================================="
  646. End If
  647. Set vdirObj = providerObj.get("IIsFtpVirtualDirSetting=""" & Server.Name & """")
  648. If (Err.Number <> 0) Then
  649. WScript.Echo L_GetSetting_ErrorMessage
  650. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  651. QueryFtpVDir = Err.Number
  652. Exit Function
  653. End If
  654. ' If this is the first binding list, print server comment and server name
  655. strVDirName = Replace(vdirObj.Name, strPath, "") ', , , vbTextCompare)
  656. WScript.Echo strVDirName & Space(25 - Len(strVDirName)) & vdirObj.Path
  657. bFirstIteration = False
  658. Next
  659. If bFirstIteration Then
  660. WScript.Echo L_VDirsNotFound_ErrorMessage
  661. End If
  662. QueryFtpVDir = ERR_OK
  663. End Function