Sample code for 30+ languages & platforms
Xbase++

Delete FTP Directory Tree

See more FTP Examples

Delete an entire directory tree on an FTP server.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "ftp.yourftpserver.com"
oFtp:Username := "****"
oFtp:Password := "****"

//  Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Set the current remote directory to the root of
//  the tree to be deleted
nSuccess := oFtp:ChangeRemoteDir("/something")
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Delete the entire tree.  All sub-directories and files are deleted.
nSuccess := oFtp:DeleteTree()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  The /something directory still exists.  To delete it,
//  we move up one directory level and then delete it.
nSuccess := oFtp:ChangeRemoteDir("..")
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

nSuccess := oFtp:RemoveRemoteDir("something")
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

nSuccess := oFtp:Disconnect()

oFtp:destroy()