Search

GlobalSCAPE Knowledge Base

Is it possible to remove a user, their home directory and all its contents using the COM interface?

Karla Marsh
EFT

THE INFORMATION IN THIS ARTICLE APPLIES TO:

  • Secure FTP Server (All Versions)
  • EFT Server (All Versions)

QUESTION

Is it possible to remove a user, their home directory and all its contents using the COM interface?

ANSWER

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:

  1. Get a reference to the user in question.
  2. Obtain the user's home folder string.
  3. Use Scripting.FileSystemObject to delete the contents of the folder. (See http://msdn2.microsoft.com/en-us/library/6kxy1a51.aspx.)
  4. 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")

SFTPServer.Connect "localhost",1100,"root","root"

set Sites=SFTPServer.Sites

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

site.removeuser("test")

after

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.

Details
Last Modified: Last Year
Last Modified By: kmarsh
Type: FAQ
Rated 1 star based on 5 votes.
Article has been viewed 41K times.
Options
Also In This Category
Tags