Lua
Lua
Append to Existing File on FTP Server
See more FTP Examples
Uploads a file to the FTP server. If the remote file (on the FTP server) does not already exist, it is created. Otherwise the uploaded file is appended to the remote file.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.myftpserver.com"
ftp.username = "myUsername"
ftp.password = "myPassword"
-- Connect to the FTP server.
local success = ftp:connect_only()
if not success then
print(ftp.last_error_text)
return
end
-- Authenticate with the FTP server.
success = ftp:login_after_connect_only()
if not success then
print(ftp.last_error_text)
return
end
local localFilePath = "/someDirectory/hamlet.xml"
local remoteFilename = "hamlet.xml"
-- Upload to the FTP server, creating the file if it does not yet exist
-- on the FTP server, or appending to the remote file if it already exists.
success = ftp:append_file(localFilePath, remoteFilename)
if not success then
print(ftp.last_error_text)
return
end
ftp:disconnect()
print("Success.")