How to support STAT LIST SFTP command on CA APIM gateway

Document ID : KB000113408
Last Modified Date : 12/09/2018
Show Technical Document Details
Case description:
CA API Gateway is acting as an SFTP server, and translating SFTP request to an HTTP call to a backend service. PUT a file was implemented, and it successfully routes via HTTP to backend services. The problem is the LIST/STAT commands which the SFTP client issues to verify the PUT has been successful. How to get the gateway to respond to these commands properly? 
xml response for LIST/STAT are the same, here is a template, 
<?xml version="1.0" encoding="UTF-8"?> 
<file file="<true/false>" lastModified="<timestamp>" 
name="<filename>" permissions="<file permission number>" size="<filesize>"/> 

<?xml version="1.0" encoding="UTF-8"?> 
<file file="true" lastModified="1535619386000" 
name="${request.ssh.file}" permissions="664" size="666"/> 

1. file="true" for a file, file="false" for a directory 
2. on sftp client, input ls (or ls -l), it will send LIST command, input ls <file> (or ls -l <file>, or change directory, etc.), it will send STAT command 
3. for LIST command response, we can have multiple <file> elements 
4. the backend needs to provide rest API to return the properties of the uploaded file as below, 
- file type (file or directory) 
- file name (could be optional, we can get it from ${request.ssh.file}) 
- last modify timestamp 
- file permission number 
- file size 

Additional Information:
The attached sample policy returns fake sftp response (it's hard coded and it's not returned from a real backend, just to show what response is accepted by what command.)
And the listen port needs to be configured to accept sftp request, here is an example,
User-added image
User-added image
User-added image
File Attachments: