Contact Us 1-800-596-4880

Connect to an SFTP Server Example - Mule 4

The following examples show how to configure Anypoint Connector for SFTP (SFTP Connector) global configuration element to:

Connect to an SFTP Server

To configure the global element to connect to an SFTP Server, follow these steps:

  1. Select the name of the connector in the Studio canvas.

  2. Select the operation in the Studio canvas.

  3. In the configuration screen for the operation, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.

  4. On the General tab, specify the connection information for the connector.

  5. Set the Working Directory field to ${workingDir}.
    This is root of every relative path used with this connector. If it’s not provided, the value defaults to the remote server.

  6. Set the Host field to specify the SFTP server host, for example localhost or 192.168.0.1.

  7. Set the Port field to ${sftpPort}.

  8. Set the Username field to anonymous and the Password field to password.

  9. On the Advanced tab, optionally specify timeout configuration and reconnection strategy.

  10. Click Test Connection to confirm that Mule can connect with the specified server.

  11. Click OK.

SFTP Connector Global Element Configuration

In the Configuration XML editor, the configuration sftp:config looks like this:

<sftp:config name="sftp">
  <sftp:connection username="anonymous" password="password"
    host="localhost" port="${sftpPort}"
    workingDir="${workingDir}"/>
</sftp:config>

Connect to an SFTP Server Through a Proxy

To configure the global element to connect to an SFTP server through a proxy, follow these steps:

  1. Select the name of the connector in the Studio canvas.

  2. Select the operation in the Studio canvas.

  3. In the configuration screen for the operation, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.

  4. On the General tab, specify the connection information for the connector.

  5. Set the Working Directory field to ${workingDir}.
    This is root of every relative path used with this connector. If it’s not provided, the value defaults to the remote server.

  6. Set the Host field to 127.0.0.100.

  7. Set the Port field to ${SFTP_PORT}.

  8. Set the Username field to muletest1 and the Password field to password.

  9. For the Sftp proxy config field, select Edit inline, and set the following fields:

    • Host: localhost

    • Port: ${proxyPort}

    • Protocol: HTTP
      The protocol can be either HTTP, SOCKS4, or SOCKS5.

  10. On the Advanced tab, optionally specify a timeout configuration and reconnection strategy.

  11. Click Test Connection to confirm that Mule can connect with the specified server.

  12. Click OK.

SFTP Connector Global Element Configuration

In the Configuration XML editor, the configuration sftp:config looks like this:

<sftp:config name="sftp">
  <sftp:connection username="muletest1" password="password"
    host="127.0.0.100" port="${SFTP_PORT}" workingDir="${workingDir}">
      <sftp:sftp-proxy-config host="localhost" port="${proxyPort}" protocol="HTTP"/>
  </ftp:sftp-connection>
</ftp:config>
View on GitHub