sftp.createConnection(options)
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 |
|
Since |
2016.2 |
Parameters
The options
parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
Since |
---|---|---|---|---|
|
string |
required |
The host of the remote account. |
2016.2 |
|
string |
required if the |
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 |
|
string |
required if the |
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 |
|
string |
required if the |
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 |
2021.1 |
|
string |
required |
The host key for the trusted fingerprint on the server. |
2016.2 |
|
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 |
|
number |
optional |
The port used to connect to the remote account. By default, port 22 is used. |
2016.2 |
|
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 |
|
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 |
|
string |
optional |
The type of host key specified by the This value can be set to one of the following options:
|
2016.2 |
Errors
Error Code |
Thrown If |
---|---|
|
The host could not be found. |
|
A connection could not be established within the amount of time specified in the |
|
The password/username was invalid or permission to access the directory was denied. |
|
The port number is invalid. |
|
The |
|
The directory does not exist on the remote FTP server. |
|
The |
|
The |
|
The |
|
Access to the file or directory on the remote FTP server was denied. |
|
The remote FTP server does not support one of NetSuite’s approved algorithms. (for example, aes256-ctr, es192-ctr, es128-ctr) |
|
There are too many incorrect authentication attempts. |
|
No route to the host can be found. |
|
The connect was reset. |
|
The connection was closed by the host. |
|
The file’s remote path is invalid. |
|
There is an SFTP credential encoding error. |
|
The SFTP server address is unavailable. |
|
Both |
Syntax
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