How do I call FTP via a GEL script?

Document ID : KB000027049
Last Modified Date : 14/02/2018
Show Technical Document Details

Question:
How do I call FTP via a GEL script?

Answer:

Here is an example script using the FTP Tag Library

The following example illustrates how to construct a document from a JDBC data source, save it to local machine, and send the document as a file to a remote FTP site.

<gel:script 
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:ftp="jelly:com.niku.union.gel.FTPTagLibrary"
  xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
  xmlns:core="jelly:core"
  xmlns:sql="jelly:sql">

  <sql:setDataSource 
    url="jdbc:clarity:oracle://dbserver:1521;SID=clarity"
    driver="com.ca.clarity.jdbc.oracle.OracleDriver" 
    user="niku" 
    password="niku"/>
 
  <sql:query var="results">
SELECT first_name, last_name, unique_name
FROM SRM_RESOURCES
WHERE is_active=?
    <sql:param value="1"/>
  </sql:query>

  <!-- Write the file locally and then FTP it -->
  <file:writeFile fileName="c:/temp/resourceData.csv" delimiter=","
    embedded="false">

    <!-- Add a comment header to the file -->
    <file:comment value="FIRST_NAME, LAST_NAME, UNIQUE_NAME"/>

    <core:forEach items="${results.rowsByIndex}" var="row">
  
      <file:line>
        <file:column value="${row[0]}"/>
        <file:column value="${row[1]}"/>
        <file:column value="${row[2]}"/>
      </file:line>
    
    </core:forEach>

  </file:writeFile>

  <ftp:open hostName="ftpserver" port="21" user="niku"
     password="clarity">
    
    <ftp:put fileName="resourceData.csv" 
      localDir="c:/temp" remoteDir="/tmp"/>
  </ftp:open>
</gel:script>