LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • module FTP
  • create(options)
  • list()
  • class ftp.Client
  • chmod(path, mode)
  • close()
  • delete(path)
  • get(path)
  • list(path)
  • mkdir(path)
  • put(path, data)
  • rename(oldPath, newPath)
  • Example

Was this helpful?

  1. Cortex API
  2. Scripting
  3. Script Modules

FTP

In-script FTP client

Last updated 3 years ago

Was this helpful?

const ftp = require('ftp')

The File Transfer Protocol (FTP) module allows scripts to access an FTP server.

Note: You must have access to an FTP server and know the following values: host, port, username, and password.

Tip: To enable FTP for your environment, please contact support.

module FTP

create(options)

Connects an FTP client instance to a remote FTP server.

Tip: If you set the host with an IP address, you should also set the secureOption rejectUnauthorized to false to avoid potential conflicts with the domain name on the server certificate, as provided by the TLS Server Name Indication (SNI) extension.

Arguments

  • options { Object }

    • host { String = localhost } FTP server domain name or IP address.

    • port { Number = 21 } FTP server port.

    • username { String = anonymous } Username for authentication.

    • password { String = anonymous@ } Password for authentication.

    • connTimeout { Number = 10000 } Wait time in milliseconds to establish a control connection.

    • pasvTimeout { Number = 10000 } Wait time in milliseconds to establish a PASV data connection.

    • keepalive { Number = 10000 } Wait time in milliseconds to send a dummy (NOOP) command to keep the connection alive.

    • secure { String = true } Always set to true for control and data encryption.

    • secureOptions { Object } Additional options to be passed to tls.connect(), as listed below. For more details, view the .

      • ca { String, String[], Buffer, Buffer[] } Overrides default Certificate Authority (CA) certificates.

      • cert { String, String[], Buffer, Buffer[] } Defines certification chains in Privacy-Enhanced Mail (PEM) format.

      • sigalgs { String } Defines a list of supported signature algorithms.

      • ciphers { String } Replaces the cipher suite specification.

      • crl { String, String[], Buffer, Buffer[] } Defines PEM-formatted Certificate Revocation Lists (CRLs).

      • dhparam { String, Buffer } Defines Diffie–Hellman parameters.

      • ecdhCurve { String } Describes a named curve or a colon-separated list of curve NIDs or names to use for Elliptic-curve Diffie–Hellman (ECDH) key agreement. Default: ⁠.

      • honorCipherOrder { Boolean } Attempts to use the cipher suite preferences of the server instead of the client.

      • key { String, String[], Buffer, Buffer[], Object[] } Sets private keys in PEM format.

      • minVersion { String } Allows you to choose the minimum allowable TLS version from the following: 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Default: .

      • maxVersion { String } Allows you to choose the maximum allowable TLS version from the following: 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. This option cannot be used in conjunction with secureProtocol; you can only use one or the other. Default: .

      • passphrase { String } Shared passphrase used for a single private key or a PFX.

      • pfx { String, String[], Buffer, Buffer[], Object[] } Defines the PFX or PKCS12 encoded private key and certificate chain.

      • secureProtocol { String } Provides a legacy mechanism to select the TLS protocol version to use. It does not support independent control of the minimum and maximum versions. It also does not support limiting the protocol to TLSv1.3. If you wish to do so, use minVersion and maxVersion instead. Default: none, see minVersion.

      • rejectUnauthorized { Boolean = true } If true, the server certificate is verified against the supplied list of CAs.

Returns

  • { ftp.Client } A new client instance.

list()

Lists current script connections.

Returns

  • { Client[] } Active connections for this script.

class ftp.Client

chmod(path, mode)

Changes file permissions.

Arguments

  • path { String } The resource to modify.

  • mode { String } A string containing octal numbers.

close()

Closes the connection with the server.

Note: Connections are automatically closed when a script exits, which frees up resources to open another connection.

delete(path)

Deletes a file on the server.

Arguments

  • path { String } File path.

get(path)

Downloads data from the server.

Arguments

  • path { String } File path.

Returns

  • { Buffer } A buffer containing the file data.

list(path)

Lists the contents of a remote directory.

Arguments

  • path { String } The path to the directory. The default is the current working directory.

Returns

  • { Object[] } A list of directory contents.

    • type { String } Entry type:

      • d: directory

      • -: file

      • l: symlink

    • name { String } Entry name.

    • size { Number } Entry size in bytes.

    • modifyTime { date } Last modified date of the entry.

    • rights { Object } Entry access rights.

      • username { String } User access rights (rwx).

      • group { String } Group access rights (rwx).

      • other { String } Other access rights (rwx).

    • owner { String } Owner name or ID.

    • group { String } Group name or ID.

    • target { String } Symlink target.

    • sticky { Boolean } True if sticky bit is set.

mkdir(path)

Creates a new directory on the server.

Arguments

  • path { String } The directory to create.

  • recursive { Boolean = false } Creates intermediate directories as required.

put(path, data)

Uploads data to the server.

Arguments

  • path { String } The file name.

  • data { Buffer } A buffer containing the file data.

rename(oldPath, newPath)

Renames a file on the server.

Arguments

  • oldPath { String } Old file name.

  • newPath { String } New file name.

Example

const ftp = require('ftp'),

    conn = ftp.create({
        host: '<hostname>',
        port: '<port>',
        username: '<username>',
        password: '<password>',
        secureOptions: {
            rejectUnauthorized: false,
            ciphers: 'TLS_AES_256_GCM_SHA384',
            minVersion: 'TLSv1.3'
        }
    }),
    buffer = new Buffer('ftp works!')

conn.mkdir('/one/two', true)
conn.put('one/two/test.txt', buffer)
let list = conn.list('/one/two')

conn.close()

return list
conn.close()

To create an FTP client, use .

Node.js TLS module reference
tls.DEFAULT_ECDH_CURVE
tls.DEFAULT_MIN_VERSION
tls.DEFAULT_MAX_VERSION
ftp.create(options)