Sample code for 30+ languages & platforms
VBScript

Remove a Remote FTP Directory (RMD)

See more FTP Examples

Demonstrates the Chilkat Ftp2.RemoveRemoteDir method, which removes a remote directory. The only argument is the remote directory path.

Background: Most FTP servers refuse to remove a directory that is not empty, so clearing a populated folder means deleting its contents first — or using DeleteTree to clear the subtree and then removing the now-empty directory. After a removal, the cached indexed listing is not refreshed automatically; call ClearDirCache before relying on the old cache again.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Demonstrates the Ftp2.RemoveRemoteDir method, which removes a remote directory.  The only
'  argument is the remote directory path.

set ftp = CreateObject("Chilkat.Ftp2")

ftp.Hostname = "ftp.example.com"
ftp.Username = "myFtpLogin"

'  Normally you would not hard-code the password in source.  You should instead obtain it
'  from an interactive prompt, environment variable, or a secrets vault.
ftp.Password = "myPassword"

success = ftp.Connect()
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If

success = ftp.ChangeRemoteDir("public_html")
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If

'  FTP servers generally require the directory to be empty before it can be removed.
success = ftp.RemoveRemoteDir("uploads/old")
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Directory removed.")

success = ftp.Disconnect()
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If


outFile.Close