Lua
Lua
Save String Variable to File on FTP Server
See more FTP Examples
Save the contents of a string variable to a file 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.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
-- Change to the remote directory where the existing file is located.
success = ftp:change_remote_dir("junk")
if not success then
print(ftp.last_error_text)
return
end
-- Upload the contents of a string to a remote file.
local fileContents = "To be, or not to be: that is the question."
local remoteFilename = "hamletQuote.txt"
success = ftp:put_file_from_text_data(remoteFilename, fileContents, "utf-8")
if not success then
print(ftp.last_error_text)
return
end
success = ftp:disconnect()
print("String Uploaded!")