function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

FTP file stream

I am pretty sure Salesforce doesn't support this in Apex -or does it?! If not then does that mean I have to use the Streaming API? But that would involve Visualforce, and I'm hoping to find a solution only in Apex.



You can't access files from FTP in Apex Code. The Streaming API also won't help you; it's for streaming query results to your browser via Push Topics. As an example of the Streaming API, you could include a widget in the sidebar that constantly refreshes with the latest closed deals in (e.g. each opportunity that changes to "Closed Won" would appear in the stream).

There's no enough details here, so why don't you elaborate and see if we can't find a way to help you.

I see. I want to stream a text file off of a FTP server, parse it, put the results into a record, and insert it.


Also a related question; what options do I have for sending files to an external file server? I am looking for alternatives to DataLoader (export and email).


P.S. I'm glad it's sfdcfox helping out here! It's good to have confidence in the answer you are getting :)


For accessing files from an FTP server, you'll have to use a proxy. I've been meaning to write one of these myself, but I've not had an opportunity to do so. Here's how it would be laid out:


1) External HTTP-FTP or SOAP-FTP proxy waits for Apex Code to connect and request a file.

2) Apex Code calls request to the proxy.

3) Proxy calls the FTP and retrieves the file.

4) Proxy returns the file via HTTP back to Apex Code.

5) Process the data as normal in Apex Code.


For sending files to an external server, you can basically do anything you could do with a normal HTTP or SOAP connection. For example, you could set up a form on a server, and have it accept a POST from, and submit that data to the external file server. You could also use a web service that was designed to accept connections and forward them to FTP servers. You can also use's email messaging capabilities to craft an email that could be sent to a server somewhere; the server could pick off the attachments and store them on a server.


In short, there are a ton of different options available. I'll see if I can't craft a FTP proxy, it looks like it should be deadly simple using PHP. I've bookmarked this post so I don't lose it; if I come up with something, I'll let you know.


In the meantime, let me know if there's anything I can do to help point you in the right direction. File access is fairly trivial once everything is in place.


P.S. Thanks for the vote of confidence!


Fantastic Mr. Sandwich! In the meantime I will start by looking into the SF Ajax Proxy. I may come back to this post if I hit a brick wall.


Also please do share your FTP proxy if you manage to write it. Proxy is a scary thing to me!


Thanks again!


Btw I'm assuming I need a proxy only because Remote Site Settings does not support FTP sites, right?

The "interactive" nature of FTP makes it impossible to use with Apex Code callouts, and, as you observed, Remote Site Settings only allow HTTP(S) connections; this is because that is the only protocol that's in common use that is non-interactive. To illustrate, a HTTP connection is like this:



While a FTP connection is more like:


This interactivity makes the REST interface useless. What you need is a system that proxies this request, abstracting the interactivity from Apex Code and exposing the functionality as a non-interactive interface.

Hello, I'm replying to this to see if you were able to find a solution. We are basically in the same boat. We would like to download media files through an FTP server using Salesforce. Since there is a limit of 3MB on webservice calls, I wanted to know if it's possible to use the Ajax toolkit to download the file.

You can use below FTP API to integrate FTP server with Salesforce.

We have implemented a REST API which allow to directly communicate with an FTP server. This FTP API is designed for people who need to perform actions like DOWNLOAD, UPLOAD, DELETE and TRANSFER on the FTP server using REST API’s.

Blog Post:

Please let me know if you need any other information.