sftp.createConnection(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Establishes a connection to a remote FTP server.

For more information, see Setting up an SFTP Transfer and Supported Cipher Suites and Host Key Types.

Returns

sftp.Connection which represents the connection

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/sftp Module

Since

2016.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.url

string

required

The host of the remote account.

2016.2

options.passwordGuid

string

required if the keyId or secret parameter is not specified

The password GUID for the remote account.

You can create a GUID using Form.addCredentialField(options). For more information, see SFTP Authentication.

Or you can use the N/https Module to fetch the GUID value returned from a Suitelet's credential field.

You can use this in combination with key ID for two-factor authentication. You cannot use this in combination with a secret ID.

2016.2

options.keyId

string

required if the passwordGuid or secret parameter is not specifed

The script ID of the key to be used for authentication. You can upload SSH keys in PEM format at Setup > Company > Keys. For more information, see N/keyControl Module and SSH Keys for SFTP.

You can use this in combination with a GUID or secret for two-factor authentication.

2019.2

options.secret

string

required if the passwordGuid or keyId parameter is not specified

The script ID of the secret used for authentication. You can store secrets at Setup > Company > API Secrets. For more information, see Secrets Management.

You can use the secret parameter in combination with the key parameter for two-factor authentication. You cannot use the secret parameter in combination with the passwordGuid parameter.

2021.1

options.hostKey

string

required

The host key for the trusted fingerprint on the server.

2016.2

options.username

string

required

The username of the remote account. The script ID of a secret can be accepted for this parameter. You can store secrets at Setup > Company > API Secrets. For more information, see Secrets Management.

By default, the login is anonymous.

2016.2

options.port

number

optional

The port used to connect to the remote account.

By default, port 22 is used.

2016.2

options.directory

string

optional

The remote directory of the connection.

Note:

The directory parameter is required if you use a remote server that cannot resolve relative paths.

2016.2

options.timeout

number

optional

The number of seconds to allow for an established connection.

This value should be between 1 and 20 seconds.

By default, this value is set to 20 seconds.

2016.2

options.hostKeyType

string

optional

The type of host key specified by the options.hostKey parameter.

This value can be set to one of the following options:

  • dsa

  • ecdsa

  • rsa

2016.2

Errors

Error Code

Thrown If

FTP_UNKNOWN_HOST

The host could not be found.

FTP_CONNECT_TIMEOUT_EXCEEDED

A connection could not be established within the amount of time specified in the options.timeout parameter.

FTP_CANNOT_ESTABLISH_CONNECTION

The password/username was invalid or permission to access the directory was denied.

FTP_INVALID_PORT_NUMBER

The port number is invalid.

FTP_INVALID_CONNECTION_TIMEOUT

The options.timeout value is either a negative value, zero, or greater than 20 seconds.

FTP_INVALID_DIRECTORY

The directory does not exist on the remote FTP server.

FTP_INCORRECT_HOST_KEY

The options.hostKey parameter does not match the presented host key on the remote FTP server.

FTP_INCORRECT_HOST_KEY_TYPE

The options.hostKeyType parameter and provided host key type do not match.

FTP_MALFORMED_HOST_KEY

The options.hostKey parameteris not in the correct format. (for example, base 64, 96+ bytes)

FTP_PERMISSION_DENIED

Access to the file or directory on the remote FTP server was denied.

FTP_UNSUPPORTED_ENCRYPTION_ALGORITHM

The remote FTP server does not support one of NetSuite’s approved algorithms. (for example, aes256-ctr, es192-ctr, es128-ctr)

AUTHENTICATION_FAIL_TOO_MANY_INCORRECT_AUTHENTICATION_ATTEMPTS

There are too many incorrect authentication attempts.

NO_ROUTE_TO_HOST_FOUND

No route to the host can be found.

CONNECTION_RESET

The connect was reset.

CONNECTION_CLOSED_BY_HOST

The connection was closed by the host.

THE_REMOTE_PATH_FOR_FILE_IS_NOT_VALID

The file’s remote path is invalid.

SFTPCREDENTIAL_ENCODING_ERROR

There is an SFTP credential encoding error.

UNABLE_TO_GET_SFTP_SERVER_ADDRESS

The SFTP server address is unavailable.

MUTUALLY_EXCLUSIVE_ARGUMENTS

Both secret and passwordGuid are defined. The passwordGuid can be used in combination with a key but not with a secret.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/sftp Module Script Samples.

          //Add additional code
...

var objConnection = sftp.createConnection({    // establish connection to the FTP server
    username: 'username',
    keyId: 'custkey1',
    secret: 'custsecret1',
    url: 'host.somewhere.com', 
    directory: 'username/wheres/my/file',
    hostKey: myHostKey // references var myHostKey
});
...
//Add additional code 

        

Related Topics

N/sftp Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices