Connection.upload(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Uploads a file to the remote FTP server. The maximum file size that can be uploaded to is 100 MB.

Returns

void

Supported Script Types

Server scripts

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

Governance

100 units

Module

N/sftp Module

Since

2016.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.file

file.File

required

The file to upload.

2016.2

options.filename

string

optional

The name to give the uploaded file on server.

By default, the filename is the same specified by options.file.

Note:

Illegal characters are automatically escaped.

2016.2

options.directory

string

optional

The relative path to the directory where the file should be upload to.

By default, the path is set to the current directory.

Important:

This input must take the form of a relative path.

2016.2

options.timeout

number

optional

The number of seconds to allow for the file to upload.

By default, this value is set to 300 seconds.

Important:

This parameter does not specify the overall timeout limit. The value is only applied when no data is received within the specified period.

2016.2

options.replaceExisting

boolean

optional

Indicates whether the file being uploaded should overwrite any file with the name options.filename that already exists in options.directory.

If false, the FTP_FILE_ALREADY_EXISTS exception is thrown when a file with the same name already exists in the options.directory.

By default, this value is false.

2016.2

Errors

Error Code

Thrown If

FTP_NO_SUCH_FILE_OR_DIRECTORY

The file or directory does not exist.

FTP_TRANSFER_TIMEOUT_EXCEEDED

The transfer is taking longer than the specified options.timeout value.

FTP_INVALID_TRANSFER_TIMEOUT

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

FTP_FILE_ALREADY_EXISTS

The options.replaceExisting value is false and a file with the same name exists in the remote directory.

CONNECTION_RESET

The connection was reset.

THE_REMOTE_PATH_FOR_FILE_IS_NOT_VALID

The file’s remote path is invalid.

CONNECTION_CLOSED_BY_HOST

The connection was closed by the host.

FTP_PERMISSION_DENIED

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

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
...

objConnection.upload({
    directory: 'relative/path/to/remote/dir',
    filename: 'newFileNameOnServer',
    file: myFileToUpload,
    replaceExisting: true
});
...
//Add additional code 

        

Related Topics

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

General Notices