Lua
Lua
FTP Upload / Download to StringBuilder
Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder object.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes Chilkat Ftp2 to have been previously unlocked.
-- See Unlock Ftp2 for sample code.
local ftp = chilkat.Ftp2.new()
ftp.hostname = "www.my-ftp-server.com"
ftp.username = "mFtpLogin"
ftp.password = "myFtpPassword"
-- 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 sbA = chilkat.StringBuilder.new()
sbA:load_file("qa_data/hamlet.xml", "utf-8")
-- Upload the contents of sbA to the FTP server.
local bIncludeBOM = false
local remoteFilename = "hamletFromSb.xml"
success = ftp:put_file_sb(sbA, "utf-8", bIncludeBOM, remoteFilename)
if not success then
print(ftp.last_error_text)
return
end
-- Download...
local sbB = chilkat.StringBuilder.new()
success = ftp:get_file_sb(remoteFilename, "utf-8", sbB)
if not success then
print(ftp.last_error_text)
return
end
-- Verify that sbA and sbB have the exact same contents.
print("size of sbA: " .. sbA.length)
local bCaseSensitive = true
if sbA:contents_equal_sb(sbB, bCaseSensitive) then
print("Contents are equal. Success.")
else
print("Contents are NOT equal. Failed.")
end
ftp:disconnect()