Skip to Main Content
Return to Navigation

Example 8: Using the SFTP Target Connector

This section discusses how to:

Prerequisites

For the examples presented in this section, you must have an active SFTP server, as well as an account on that server.

Uploading Files to an SFTP Server

To upload a file to an SFTP server:

  1. Add a new URL object.

    1. Select select PeopleTools, then select Utilities, then select Administration, then select URLs.

      The URL Maintenance page appears.

    2. Add the following values:

      Field

      Value

      URL Identifier

      SFTPTESTURL

      Description

      SFTP Server URL

      URLID

      Enter the appropriate URL. For example:

      sftp://<userid>:<password>@<address>:<port>
    3. Save the changes.

  2. In PeopleSoft Application Designer, open the EXAMPLE_WORKREC record and add the following PeopleCode to the FieldChange event for the TEST field:

    Local array of Message &messages;
    Local array of Message &responses;
    Local Message &MSG;
    Local array of string &nodenames;
    Local string &node;
    
    &xmldata = "<?xml version='1.0'?><sftpTest/>";
    
    &xmlDoc = CreateXmlDoc(&xmldata);
    
    &rootNode = &xmlDoc.documentelement;
    &descNode = &rootNode.AddElement("Payload");
    &descNode.NodeValue = "Generated at " | %Datetime;
    
    
    &messages = CreateArrayRept(&MSG, 0);
    &nodenames = CreateArrayRept(&node, 0);
    
    &nodenames [1] = "TARGETNODE";
    &messages [1] = CreateMessage(Operation.EXAMPLE_SERVICE_OPR);
    &messages [1].SetXmlDoc(&xmlDoc);
    
    &responses = %IntBroker.SyncRequest(&messages, &nodenames);
    
  3. In the PeopleSoft Pure Internet Architecture, open the TARGETNODE node definition and do the following:

    1. On the Node Definitions-Connectors tab, set the Connector ID to SFTPTARGET.

    2. Set the following properties to the values indicated:

      Property

      Value

      BASE64ENCODE

      Y.

      CHARSET

      UTF-8.

      METHOD

      PUT.

      REMOTEFILENAME

      SFTPTestFile.txt.

      URL

      SFTPTESTURL.

  4. In the PeopleSoft Pure Internet Architecture, open the EXAMPLE_PAGE page and click the Test button.

    Login to the SFTP server and check for the file. Open the SFTPTestFile.txt file and verify the contents.

Downloading Binary Files from SFTP Servers

To download a binary file from an SFTP server:

  1. Put a binary file in an accessible location on the SFTP server.

    For this example, the file is called image.jpg.

  2. Add a new URL object.

    1. Select select PeopleTools, then select Utilities, then select Administration, then select URLs.

      The URL Maintenance page appears.

    2. Add the following values:

      Field

      Value

      URL Identifier

      SFTPTESTURL

      Description

      SFTP Server URL

      URLID

      Enter the appropriate URL. For example:

      sftp://<userid>:<password>@<address>:<port>
    3. Save the changes.

  3. In PeopleSoft Application Designer, open the EXAMPLE_WORKREC record and add the following PeopleCode to the FieldChange event for the TEST field:

    Local array of Message &messages;
    Local array of Message &responses;
    Local Message &MSG;
    Local array of string &nodenames;
    Local string &node;
    
    &xmldata = "<?xml version='1.0'?><sftpTest/>";
    
    &xmlDoc = CreateXmlDoc(&xmldata);
    
    &messages = CreateArrayRept(&MSG, 0);
    &nodenames = CreateArrayRept(&node, 0);
    
    &nodenames [1] = "TARGETNODE";
    &messages [1] = CreateMessage(Operation.EXAMPLE_SERVICE_OPR);
    &messages [1].SetXmlDoc(&xmlDoc);
    
    &responses = %IntBroker.SyncRequest(&messages, &nodenames);
    
    
    &theTempFile = GetFile("C:\work\aNewImage.jpg", "W", %FilePath_Absolute);
    If &theTempFile.IsOpen Then
       &theTempFile.writeBase64StringtoBinary(&responses [1].GetContentString());
       &theTempFile.Close();
    End-If;
  4. In the PeopleSoft Pure Internet Architecture, open the TARGETNODE node definition and do the following:

    1. On the Node Definitions-Connectors tab, set the Connector ID to SFTPTARGET.

    2. Set the following properties to the values indicated:

      Property

      Value

      BASE64ENCODE

      N.

      CHARSET

      UTF-8.

      METHOD

      GET.

      REMOTEFILENAME

      image.jpg

      URL

      SFTPTESTURL.

  5. In the PeopleSoft Pure Internet Architecture, open the EXAMPLE_PAGE page and click the Test button.

    Check the local directory for the file. Open the file and verify the contents.