Skip to Content

One of the recurring inquiries in SAP Sourcing has been the use of FTP within scripts. While this might be a simple task in Java, the biggest problem is that Sourcing 9.x doesn’t use the all-too-familiar Apache Commons FTPClient.

In this blog post I will explain how to make use of the internal functions available in SAP Sourcing 9.x to facilitate working with FTP folders.

**WARNING**– this blog post will make use of Internal APIs. Even if I have tested and confirmed them working in 9.x versions, great care should be taken while implementing and supporting these APIs.

  • Prerequisites:
    • Check and confirm that your FTP integration System Properties are defined and access is granted to respective directory.

Screen Shot 2015-06-02 at 12.13.04 AM.png

The fun part: scripting

  • Import some classes

import java.io.*;
import java.util.*;
import com.sap.eso.sapintegration.util.SapIntUtil;
import com.sap.odp.doc.integration.IntegrationConfig;

  • Define your FTP Server

//CONSTANTS
String FTP_SERVER = "10.10.10.10";
String FTP_USER = "MyFtpUsername";
String FTP_PASSWORD = "MyFtpPassword";
String FTP_OUTBOUND_DIRECTORY = "my/outbound/directory";

  • Prepare your file
    • Let’s assume you have an AttachmentIfc you want to push to FTP location

File exportFile = attachmentIfc.getFileData(session);

String xmlString = "sample XML text";
tempDirectory = IntegrationConfig.getEnterpriseProperty(session, "ftp.temp_dir");
File exportFile = new File(tempDirectory + File.separator + "my_file.xml");
writer = new OutputStreamWriter(new FileOutputStream(exportFile), "UTF-8");
writer.write(xmlString);
writer.close();

  • Finally, write your File to FTP

SapIntUtil.instance().ftpFile(session, exportFile.getParent(), FTP_OUTBOUND_DIRECTORY, FTP_SERVER, FTP_USER, FTP_PASSWORD, exportFile.getName());

**PS** For SAP Sourcing 10.x a different post will follow because the changes introduced allow for a better implementation with the use of File Transfer Configuration

Bogdan Toma

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    Hi Former Member ,

    We have SAP Sourcing 9. Is there a way we can create directories on ftpServer through scripting using internal APIs. We want to push our Contract Documents to FTP server and to be able to distinguish between documents of different MAs we need to create a directory at run time and then push the documents to the newly created directory.

     

    BR,

    Kunal

     

    (0) 

Leave a Reply