Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

In this tutorial, we will cover how you can connect to a SFTP/FTP server using the translator.

Note: For building SFTP/FTP connections using a pre-built component refer to the From FTP documentation.

For building SFTP/FTP connections in the translator:

 STEP 1: Initialize connection

Use the net.sftp.init command to initialize the connection. You only need to use the following five parameters:

Parameter

Description

Server

The server to connect to. string

Username

The remote user to login as. string

Password

The password to authenticate with. string

Port

The port to use (default = 22). integer

Timeout

Timeout for operations (default = 15 seconds). integer

 STEP 2: Translator Code

Your net.sftp.init code will look something like this:

local Conn = net.sftp.init{
  server=Destination_HostName,
  username=Destination_Login,
  password=Destination_Password,
  port=Destination_Port,
  timeout = 60,
  }

 STEP 3: Send and receive files via SFTP/FTP

Here is a sample script showing how you can use the net api to list, get and put a file via SFTP:

function main(Data)
  
-- (1) Initialize Connection

local Conn = net.sftp.init{
  server=Destination_HostName,
  username=Destination_Login,
  password=Destination_Password,
  port=Destination_Port,
  timeout = 60,
  }

-- (2) List files from SFTP Server
local list = Conn:list{remote_path="/"}

-- (3) Get a file from the SFTP server
local get = Conn:get{remote_path='afile.txt'}

-- (4) Put a file on the SFTP Server
local put = Conn:put{remote_path='sample.txt', data=Data}

end
  • No labels