Be Good & Do Good!

Salesforce – FTP Integration (Data loader, Web service & HTTP)

Author : Chirag Mehta & Angelica Buffa

Using FTP servers to store and share files is very common now at days. Most language programs let you develop FTP clients and consume their services.

With Apex, there are three possible approaches to resolve the integration with this kind of file servers:

I – Data Loader CLI – Windows approach.

  1. Download Salesforce Data Loader Command Line Interface (Read more at http://wiki.developerforce.com/index.php/Using_Data_Loader_from_the_command_line)
  2. Write a Widows Batch file (.bat file)
  3. First command in the batch file will be connect to FTP server (ms-dos command ‘ftp’) and then get the necessary files from ftp server to the local folder.
  4. Second set of commands execute the Data Loader CLI jar and loads step3 retrieved file into Salesforce.
  5. To automate the execution of the batch, we can schedule the bat file execution using scheduled task feature of Windows operating system.

II – Java Web Service

  1. Write a Java FTP client, expose it as a Web Service
  2. Consume above WS into your Salesforce Org using Apex “Browse WSDL” functionality

III – Http Request

  1. Create a Http Request to the FTP server
  2. Handle the response using either of HttpRequest and HttpResponse Apex Class
  3. Ps: The problem that you can face is the size of the files. Please remember that HTTP Request size are currently limited to 100Kb of data, so larger exports would fail unless a mechanism was created to utilize multi-part transmissions.

10 Comments

  1. indira

    Thank you for making this information available on net …

    Nice site too.

  2. Srinivas

    I liked the explanation very much. It would be helpful if you could share any examples

  3. Srinivas

    Hi Chirag,

    Is there a provision in Salesforce to connect to an FTP server to import files.

    I am working on the SAP team and we wanted to set up file transfer from SAP to Salesforce. The vendor was suggesting API and use of integration engine. But considering the current SAP set up in use and time constraints involved for this delivery, the quickest solution for file transfer would be to give them access to our FTP server , to which files transmission would be scheduled on daily basis from SAP.

    Can you please let me know if this is possible?

    Please mail me @ jg.srinivas@gmail.com

    Thanks and Regards,
    Srinivas

  4. Tulsi

    Hi Chirag,
    Can you please share some sample code that you have implemented for sending data to a FTP Server. It would be helpful. I just need a confirmation that this is possible?

    Thanks,
    Tulsi

  5. Chirag Mehta

    I’ve not implemented one. These were more of approaches that one could take to achieve the output, not sure in terms of feasibility of the same. Logically there needs to be a web-service on ftp server which can then later be consumed by consumer to do ftp data transfer.

  6. Chirag Mehta

    @Sam : These allows to import/export data from files (csv) or oracle/sql-server to Salesforce. What we are looking here is to import/export from ftp to Salesforce.

  7. SF User

    Hi Chirag

    I want to transfer a file, stored in Document object in Salesforce, to FTP. Kindly let me know if there is any helpful link.

    Thanks
    SF User

  8. Chirag Mehta

    You will need first thing is a service which does FTP over web, and then you will need to make callout to that webservice. This post that I tried to document is an approach, not sure if anyone implemented something similar or not.

  9. Dinesh Singla

    HI chirag

    i am able to do ftp integration using I – Data Loader CLI – Windows approach. but i dont want to use my local system so now i trying with 3rd approach but i am not able to connect.can u plz provide any example code or some link

    thanks & regards
    dinesh

Leave a Reply

Your email address will not be published. Required fields are marked *