Transferring files to and from a collective member or registered host with REST calls

You can perform routed file transfer operations from a collective controller to a collective member or to a registered host of a collective by invoking REST APIs. The operations include downloading files from a remote location, uploading files to a remote location, and deleting files in a remote location. Use the GET, POST, or DELETE REST APIs. The file transfer operations occur within an IBM JMX REST Connector.

Before you begin

To perform file transfer operations from a collective controller to a member server, the server must be joined as a member to the collective. See Configuring a Liberty collective.

To perform file transfer operations to a host computer, the host must be registered with the collective controller. See Registering host computers with a Liberty collective.

Procedure

  1. Optional: To read about the REST APIs, point a browser at https://controller_host_name:controller_port_name/IBMJMXConnectorREST/api and enter the controller administrative user ID and password to log in. The controller must be running to view the REST API documentation. Alternatively, you can use a collective member host, port, login user ID and password to view the REST API documentation.

    The File Transfer and Routing sections describe the APIs used to transfer files between the collective controller and a member server or a registered host.

    The collectiveController-1.0 and collectiveMember-1.0 features enable the restConnector-1.0 feature, which provides file transfer capability. Thus, collective controllers and members do not need to specify restConnector-1.0 in a feature manager to view the REST APIs or perform file transfer operations. A stand-alone server configuration might need the restConnector-1.0 feature to view the REST APIs. The restConnector-2.0 feature is tolerated.

  2. Unless you work directly with a Liberty instance, set the routing context as HTTP headers.
    • Member server routing
      com.ibm.websphere.jmx.connector.rest.routing.hostName=string
      com.ibm.websphere.jmx.connector.rest.routing.serverName=string
      com.ibm.websphere.jmx.connector.rest.routing.serverUserDir=string
    • Registered host routing
      com.ibm.websphere.jmx.connector.rest.routing.hostName=string
  3. Ensure the target file is within the configurable read/write directories of the server for file transfer operations with a member server, or within configurable read/write directories of the host for file transfer operations with a registered host.
  4. Invoke REST APIs that download, upload, or delete files.

    {filePath} must be URL-encoded. For routing operations with registered hosts, {filePath} must be an absolute path and cannot contain Liberty variables.

    • Download one file from a member server or registered host using the GET operation.
      GET https://controller_host:controller_port/IBMJMXConnectorREST/file/{filePath}
    • Upload one file to a member server or registered host using the POST operation.
      POST https://controller_host:controller_port/IBMJMXConnectorREST/file/{filePath}
    • Delete one file from a member server or registered host using the DELETE operation.
      DELETE https://controller_host:controller_port/IBMJMXConnectorREST/file/{filePath}
    • Delete multiple files from a member server or registered host using the POST operation.
      POST https://controller_host:controller_port/IBMJMXConnectorREST/file/collection

Example

To download the myFile.txt file from the member server myServerA on the host myTarget.com with a user directory of C:/server/wlp:
  1. Set the member server routing context as HTTP headers.
    com.ibm.websphere.jmx.connector.rest.routing.hostName=myTarget.com
    com.ibm.websphere.jmx.connector.rest.routing.serverName=myServerA
    com.ibm.websphere.jmx.connector.rest.routing.serverUserDir=C:/server/wlp
  2. Invoke a GET call to download the file.
    GET https://myTarget.com:9443//IBMJMXConnectorREST/file/C%3A%2Ftemp%2FmyFile.txt
To download the myFile.txt file from the registered host myTarget.com:
  1. Set the registered host routing context as an HTTP header.
    com.ibm.websphere.jmx.connector.rest.routing.hostName=myTarget.com
  2. Invoke a GET call to download the file.
    GET https://myTarget.com:9443//IBMJMXConnectorREST/file/C%3A%2Ftemp%2FmyFile.txt
To download the server.xml file from the member server myServerA on the host myTarget.com with a user directory of C:/server/wlp:
  1. Set the member server routing context as HTTP headers.
    com.ibm.websphere.jmx.connector.rest.routing.hostName=myTarget.com
    com.ibm.websphere.jmx.connector.rest.routing.serverName=myServerA
    com.ibm.websphere.jmx.connector.rest.routing.serverUserDir=C:/server/wlp
  2. Invoke a GET call to download the ${server.config.dir}/server.xml file.
    GET https://myTarget.com:9443//IBMJMXConnectorREST/file/%24{server.config.dir}%2Fserver.xml

What to do next

Get status or details on the REST call. See Getting status on a REST call for multiple registered hosts.