Handling FTP_FILE_ALREADY_EXISTS Error in N/sftp SuiteScript Module

When using the N/sftp SuiteScript module to transfer files via SFTP in NetSuite, you may encounter the error “FTP_FILE_ALREADY_EXISTS.” This error typically occurs when attempting to upload a file that already exists on the remote server. However, in some cases, this issue may be due to a missing system preference in your NetSuite account.

Understanding the Error:

The FTP_FILE_ALREADY_EXISTS error message is thrown by the N/sftp module when:

  1. A file with the same name already exists in the target directory, and the SFTP server does not allow overwriting.
  2. The NetSuite account is missing a required system preference: “SFTP: Use List to test that a file exists.” This preference is not currently available in the NetSuite UI and must be enabled by NetSuite Support.

Possible Solutions:

1. Check If the File Already Exists on the SFTP Server

Before transferring the file, verify whether it already exists in the target directory. You can use the list method in the N/sftp module to check for existing files:

define([‘N/sftp’], function(sftp) {

  function checkFileExists(connection, remoteFilePath) {

    var fileList = connection.list({ path: ‘/’ }); // Adjust path as needed

    return fileList.some(file => file.name === remoteFilePath);

  }

});

If the file exists, consider renaming the new file before transferring it.

If the server allows overwriting, modify your transfer logic accordingly.

2. Contact NetSuite Support

If you have confirmed that the file does not exist but are still receiving the error, your account may require the “SFTP: Use List to test that a file exists” preference. Since this setting is not available in the NetSuite UI, you will need to open a support case with NetSuite to request its activation.

The FTP_FILE_ALREADY_EXISTS error can be caused by either an actual file conflict or a missing system preference in NetSuite. To resolve this issue:

  1. First, confirm whether the file already exists using the list method.
  2. If the issue persists, contact NetSuite Support to request the “SFTP: Use List to test that a file exists” setting.

By following these steps, you can ensure smoother file transfers using the N/sftp SuiteScript module.

Leave a comment

Your email address will not be published. Required fields are marked *