Lua
Lua
Delete FTP Directory Tree
See more FTP Examples
Delete an entire directory tree on an FTP server.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local ftp = chilkat.Ftp2.new()
ftp.hostname = "ftp.yourftpserver.com"
ftp.username = "****"
ftp.password = "****"
-- Connect and login to the FTP server.
local success = ftp:connect()
if not success then
print(ftp.last_error_text)
return
end
-- Set the current remote directory to the root of
-- the tree to be deleted
success = ftp:change_remote_dir("/something")
if not success then
print(ftp.last_error_text)
return
end
-- Delete the entire tree. All sub-directories and files are deleted.
success = ftp:delete_tree()
if not success then
print(ftp.last_error_text)
return
end
-- The /something directory still exists. To delete it,
-- we move up one directory level and then delete it.
success = ftp:change_remote_dir("..")
if not success then
print(ftp.last_error_text)
return
end
success = ftp:remove_remote_dir("something")
if not success then
print(ftp.last_error_text)
return
end
success = ftp:disconnect()