Connecting via FTP on a business modeling platform — MODLR

Adithya
1 min readMar 3, 2021

--

We have been using MODLR for a while for our connected planning tool, once we decided to move out of excel spreadsheets. One of the situations we found ourselves in recently was to implement file transfer from our server to MODLR to import data automatically.

We created a Process in our data model and then went over to the script editor in Javascript to start with.

  • Create a new FTP connection (we use model variables so we can keep this clean)

var client = ftp.Connect(protocol, host, port, username, password);

Reference from the docs:
protocol — The ftp protocol for this connection. At the moment, only “sftp” is supported.
host — The ftp host like a domain name or an ip address
port — The port to use on the ftp connection
username — The username to use
password — The password for the user

  • Check if the connection was successful and transfer file
if (client.IsConnected()) {// Transfer file
var result = client.Upload('WeeklyReport.csv', '/var/www/html/weekly-reports/');
//returns a boolean based on the result
} else {
//send a sms notification using notifications.sms
}

--

--

Adithya
Adithya

Written by Adithya

Backend developer from Berlin, building https://arbeitnow.com/

No responses yet