Lua
Lua
Rename Remote File
See more FTP Examples
Rename a remote file or directory. The RenameRemoteFile can be called to rename either a remote file or directory.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.example.com"
ftp.username = "login"
ftp.password = "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 where the file
-- is located:
success = ftp:change_remote_dir("/testing")
if not success then
print(ftp.last_error_text)
return
end
-- Rename the remote file (or directory)
local existingFilename = "hello.txt"
local newFilename = "goodbye.txt"
success = ftp:rename_remote_file(existingFilename, newFilename)
if not success then
print(ftp.last_error_text)
return
end
success = ftp:disconnect()