PureBasic
PureBasic
Delete FTP Directory Tree
See more FTP Examples
Delete an entire directory tree on an FTP server.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.yourftpserver.com")
CkFtp2::setCkUsername(ftp, "****")
CkFtp2::setCkPassword(ftp, "****")
; Connect and login to the FTP server.
success = CkFtp2::ckConnect(ftp)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; Set the current remote directory to the root of
; the tree to be deleted
success = CkFtp2::ckChangeRemoteDir(ftp,"/something")
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; Delete the entire tree. All sub-directories and files are deleted.
success = CkFtp2::ckDeleteTree(ftp)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; The /something directory still exists. To delete it,
; we move up one directory level and then delete it.
success = CkFtp2::ckChangeRemoteDir(ftp,"..")
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
success = CkFtp2::ckRemoveRemoteDir(ftp,"something")
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
success = CkFtp2::ckDisconnect(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure