Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Custom implementation to support FTPS

SA-133

Summary



Unable to implement FTPS to transfer file from PRPC to a remote FTPS server via FTP on SSL.

Steps to Reproduce



Use Connect-FTP method to send file from PRPC system to a FTPS server.

Root Cause



Pega 7.1.5 does not provide out of the box infrastructure to transfer files using FTPS from PRPC to remote FTP server. Pega also does not ship the latest commons-net-3.3.jar from Apache with the implementation to FTPSClient code.

Resolution



1. Download the latest commons-net-3.3.jar from Apache and place it inside the 'lib' folder of Tomcat.
2. Restart Tomcat
3. Lookup org.apache.commons.net.ftp.FTPSClient in SMA ETier Runtime and copy Location value to compiler/defaultPaths dynamic system setting.  If Value of Location is --> file:/D:/pegaapp1/v715oracle/apache-tomcat-7/lib/commons-net-3.3.jar then copy D:\pegaapp1\v715oracle\apache-tomcat-7.0.22\lib\commons-net-3.3.jar" and paste to "compiler/defaultPaths" dynamic system setting
4.In SMA go to Advanced --> Class Management  --> Refresh External Jars
5. Create a new Activity and include the following Java code in the Java step, follow the comments in the code to replace values.
  

boolean error = false;

/** localFile variable holds reference to file on the PRPC server
    TODO: Update localFile variable to point to a file that needs
 to be sent over FTPS.
 example:
 String localFile = "F:\\TestFile.txt";
 **/
String localFile = "";
org.apache.commons.net.ftp.FTPSClient ftps = new org.apache.commons.net.ftp.FTPSClient("SSL", true);
try {
 int reply;
 ftps.setAuthValue("SSL");
 /** Enter the fully qualified name and port of the FTPS server
  example:
  ftps.connect("hostname", 990);
 **/
 ftps.connect("", 990);
 /** Enter the user credentials to access FTPS server
  example:
  ftps.login("admin", "admin");
 **/
 ftps.login("", "");
 ftps.execPBSZ(0);
 ftps.execPROT("P");

 reply = ftps.getReplyCode();
 if (!org.apache.commons.net.ftp.FTPReply.isPositiveCompletion(reply)) {
  ftps.disconnect();
  oLog.info("FTP server refused connection.");
  throw new PRRuntimeException("Could not connect to the FTP server");
 }
} catch (java.io.IOException e) {
 if (ftps.isConnected()) {
  try {
   oLog.info("ERROR. Disconnecting from the FTP server.");
   ftps.disconnect();
  } catch (java.io.IOException f) {
   // do nothing
  }
 }
 throw new PRRuntimeException("Error establishing connection with FTP server.", e);
}

try {
 ftps.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); // can be BINARY or ASCII
 ftps.enterLocalPassiveMode();
 java.io.InputStream input = new java.io.FileInputStream(localFile);
 /** Name the file as you want it on the FTPS server, usually its the same as source
  ftps.storeFile("TestFile.txt", input);
 **/
 ftps.storeFile("", input);
 ftps.logout();
} catch (org.apache.commons.net.ftp.FTPConnectionClosedException e) {
 error = true;
 oLog.error("Server closed connection.");
 throw new PRRuntimeException("Server closed connection", e);
} catch (java.io.IOException e) {
 error = true;
 oLog.error("Error sending file: " + e.getMessage());
 throw new PRRuntimeException("Error sending file.", e);
} finally {
 oLog.info("Logging out of the session.");
 if (ftps.isConnected()) {
  try {
   oLog.info("Disconnecting from the FTP server.");
   ftps.disconnect();
  } catch (java.io.IOException f) {
   // do nothing
  }
 }
}

Published February 22, 2016 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice