DEV Community

adithyasrinivasan
adithyasrinivasan

Posted on

3 2

Connecting via FTP on MODLR

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 connecton. 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
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay