Lua
Lua
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData 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 bdA = chilkat.BinData.new()
bdA:load_file("qa_data/jpg/penguins.jpg")
-- Upload the contents of bdA to the FTP server.
local remoteFilename = "penguins.jpg"
success = ftp:put_file_bd(bdA, remoteFilename)
if not success then
print(ftp.last_error_text)
return
end
-- Download...
local bdB = chilkat.BinData.new()
success = ftp:get_file_bd(remoteFilename, bdB)
if not success then
print(ftp.last_error_text)
return
end
-- Verify that bdA and bdB have the exact same contents.
print("size of bdA: " .. bdA.num_bytes)
if bdA:contents_equal(bdB) then
print("Contents are equal. Success.")
else
print("Contents are NOT equal. Failed.")
end
ftp:disconnect()