Skip to content

SFTPService

Dmytro Katashev edited this page Aug 12, 2024 · 1 revision

SFTPService API Reference

Overview

The SFTPService class extends the BaseService class, providing specialized functionality for interacting with SFTP and FTP services in Salesforce Commerce Cloud (SFCC). It manages the creation of protocol-specific clients, execution of SFTP/FTP operations, and offers flexibility for both single and multiple operations.

Inherits from: BaseService


Public Methods

fetch(params: SFTPParams)

Description: Executes an SFTP/FTP service call based on the provided parameters. It utilizes the initServiceClient and execute methods to manage the client connection and handle the specified operation.

  • Parameters:
    • params (SFTPParams): The parameters for creating and executing the SFTP/FTP service request.
  • Returns:
    • dw.svc.Result: The result of the service call, either success or error.

initServiceClient(svc: dw.svc.FTPService)

Description: Creates a protocol-specific client object (either FTP or SFTP) based on the service configuration and credentials.

  • Parameters:
    • svc (dw.svc.FTPService): The FTP/SFTP service instance.
  • Returns:
    • Object: The initialized client object (either dw.svc.FTPClient or dw.svc.SFTPClient).

execute(svc: dw.svc.FTPService, params: SFTPParams)

Description: Executes the specified SFTP/FTP operation. Supports both single and multiple operations via callbacks.

  • Parameters:
    • svc (dw.svc.FTPService): The FTP/SFTP service instance.
    • params (SFTPParams): The parameters for executing the operations.
  • Returns:
    • *: The result of the executed operation.
  • Throws:
    • Error: If no valid operation with arguments or execute callback is provided.

Protected/Internal Methods

_getClient(protocolType: string)

Description: Returns an FTP or SFTP client based on the specified protocol type.

  • Parameters:
    • protocolType (string): The protocol type (ftp or sftp).
  • Returns:
    • dw.net.FTPClient | dw.net.SFTPClient: The initialized client object.
  • Throws:
    • Error: If the protocol type is not recognized.

Types and Callbacks

SFTPParams

Represents parameters for the SFTP/FTP service.

  • Type: Object
    • operation ('cd' | 'del' | 'get' | 'getBinary' | 'getFileInfo' | 'list' | 'mkdir' | 'put' | 'putBinary' | 'removeDirectory' | 'rename'): The SFTP/FTP operation to be executed.
    • args (*[]): The arguments for the operation.
    • onExecute (function): Callback function for executing multiple operations.

onExecute

Callback function for executing SFTP/FTP operations.

  • Type: function
    • Parameters:
      • svc (dw.svc.FTPService): The FTP/SFTP service instance.
    • Returns:
      • *: The result of the executed operations.

Clone this wiki locally