Lua
Lua
AWS Transfer for SFTP (Amazon S3)
See more SFTP Examples
Once you've setup your AWS Transfer for SFTP in the AWS Console, interacting with it is no different than any other SSH/SFTP server. AWS will provide a private key in PEM format. It is used for authentication (instead of a password).Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local sftp = chilkat.SFtp.new()
-- Connect to the AWS SFTP server.
-- Change the domain to your value.
local domain = "s-123456df999999fab.server.transfer.eu-west-2.amazonaws.com"
local port = 22
local success = sftp:connect(domain, port)
if not success then
print(sftp.last_error_text)
return
end
-- Load your AWS SFTP private key PEM file..
local sshKey = chilkat.SshKey.new()
local keyText = sshKey:load_text("qa_data/pem/s3_sftp_privateKey.pem")
if not sshKey.last_method_success then
print(sshKey.last_error_text)
return
end
success = sshKey:from_open_ssh_private_key(keyText)
if not success then
print(sshKey.last_error_text)
return
end
-- Authenticate with the SSH server using the private key.
success = sftp:authenticate_pk("myUsername", sshKey)
if not success then
print(sftp.last_error_text)
return
end
-- After authenticating, the SFTP subsystem must be initialized:
success = sftp:initialize_sftp()
if not success then
print(sftp.last_error_text)
return
end
-- Upload from the local file to the SSH server.
-- Important -- the remote filepath is the 1st argument,
-- the local filepath is the 2nd argument;
local remoteFilePath = "hamlet.xml"
local localFilePath = "c:/temp/hamlet.xml"
success = sftp:upload_file_by_name(remoteFilePath, localFilePath)
if not success then
print(sftp.last_error_text)
return
end
print("Success.")