THE INFORMATION IN THIS ARTICLE APPLIES TO:
- Secure FTP Server (All Versions)
- EFT Server (All Versions)
Is it possible to remove a user, their home directory and all its contents using the COM interface?
You can use a combination of EFT Server's COM methods and built-in Windows objects, like FileSystemObject, to delete a user's home folder and all of its contents. EFT Server provides a RemoveFolder() method; however, this only works if the folder is empty.
Perform the following steps to delete a folder that may be populated with content:
- Get a reference to the user in question.
- Obtain the user's home folder string.
- Use Scripting.FileSystemObject to delete the contents of the folder. (See http://msdn2.microsoft.com/en-us/library/6kxy1a51.aspx.)
- Use RemoveFolder() to get rid of the folder from EFT VFS. This step is only required if the folder in question is VIRTUAL; if it is physical, then the step above can be extended to delete the folder and its contents, not just its contents.
The sample script below assumes that the VFS path from site root down to the user
home folder does NOT have any virtual path mappings in the tree, otherwise the logic will need to be updated:
SFTPServer.Connect "127.0.0.1", 1100, "admin", "admin"
Set SFTPServer = CreateObject("SFTPCOMInterface.CIServer")
set site = Sites.Item(0)
Set oSettings = site.GetUserSettings("test")
strHomeDir = Replace( oSettings.GetHomeDirString(), "/", "\" ) ' Get the User's home folder in VFS form
strHomeDir = site.GetRootFolder() & Right(strHomeDir, Len(strHomeDir)-1) ' add the virtual path to the site root folder to get physical path
WScript.Echo "Going to delete folder '" & strHomeDir & "'"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Call oFSO.DeleteFolder( strHomeDir, True )
Set oFSO = Nothing
WScript.Echo "Removed Home directory."
Set site = Nothing
Set SFTPServer = Nothing
If you want to remove the user account also, insert
Set site = Nothing
Refer to EFT Server COM API Scripts for more script examples.
Refer to the latest version of the COM API help documentation for details of using each of the properties and methods.
Optionally provide private feedback to help us improve this article...
Thank you for your feedback!