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
Cool_DevloperCool_Devloper 

Creating a CSV file from salesforce and sending to FTP server

Hello Friends,

 

I have a requirement wherein the users will click on a button and a CSV file should be generated with some data. Now this file should be automatically sent to an FTP server in real time.

 

Can this be achieved in salesforce by any means?

 

Please Help!

Cool_D

sfdcfoxsfdcfox
While you can create a CSV file within Apex Code, there's no real functionality for making a call to an FTP server. About the best I could recommend would be to perform an HTTP post, and have that intermediary server save the file to the FTP server. FTP is by definition interactive (it involves two ports and some binary protocols), and Salesforce's callout functionality is non-interactive (i.e. you send a single HTTP-style message, and receive a response in an HTTP-style response, which may well be encoded binary or XML). A determined attempt to do this using an HTTP gateway would certainly succeed. Also, please remember that strings are currently limited to 100Kb of data, so larger exports would fail unless a mechanism was created to utilize multi-part transmissions.
Cool_DevloperCool_Devloper

Thanks sfdcfox for the elaborate explanation :)

 

I just wat to understand how this thing actually works. Like, when i make a HTTP Post to a server, is the complete file transferred over the wire?

 

How does the server save the attachment fetching it from from salesforce? And if this is possible, then do i need to send the attachment link to this server?

 

Many Thanks,

Cool_D

sfdcfoxsfdcfox

This requires two components that would work in tandem. First, you need an appropriate Apex Class that can perform the transfer. This utilities the Http, HttpRequest, and HttpResponse objects. The "method" would be set to "POST", the endpoint would be set to your server's URL, and the Body would be set to the CSV string you are sending (or Base64, if you prefer). The second part would be a service hosted on your web server that accepts the file (i.e. http://www.mycompany.com/cgi-bin/fileupload.php). You may provide authentication if you prefer (to prevent abuse, DOS attacks, etc). The pseudocode would be as follows:

 

1) Query for the selected items.

2) Construct the CSV string.

3) (Optional) Convert to base64.

4) Construct the connection, and send the file, using whichever authentication you prefer.

5) (Optional) Read the response to ensure a successful transfer.

 

The server side would be as follows:

 

1) (Optional) Verify authentication.

2) Read from the standard input stream until all bytes are transferred.

3) Save the file to the storage medium, or transfer it via FTP to the final destination.

4) Provide some type of response.

 

Ultimately, the specifics of the entire process will depend on your server's capabilities as well as the skills of you or your web developer.

Cool_DevloperCool_Devloper
Thanks SFDCFox!!

I do understand this after the elaborate explaination!!

So, basically here we are calling a service over a server which will save the file for us.

Is there any other way apart from using a Webservice to do this file transfer?? You know the limit is 100KB and unfortunately the size of attachments in this case is huge! :(

Cool_D
ChangeForceChangeForce

Hi sfdcfox,

 

I need to construct a CSV file with APEX and am a bit new to the game.  Do you have any sample code I could get started with, or resources that you can point me to?

 

Thanks in advance.

sri14sri14

Can you please explain about below things with sample code:

FYI, i am able to construct the CSV string and

tell me about connection construction ...etc as you mentioned like: in 4th and 5th step( How i ensure,whether my data is transfered successfully or not..

 

4) Construct the connection, and send the file, using whichever authentication you prefer.

5) (Optional) Read the response to ensure a successful transfer

The server side would be as follows:

1) (Optional) Verify authentication.

2) Read from the standard input stream until all bytes are transferred.

3) Save the file to the storage medium, or transfer it via FTP to the final destination.

4) Provide some type of response.

Jack Daniel 11Jack Daniel 11
Hi SFDCfox/Cool_Developer/ChangeForce/Sri14
What are the various approaches to send extracted CSV file from Salesforce to Dropzone via SMS(Internal ETL) step by step- New to SFDC:( Pls help
I'm new to salesforce. Please help me with the data extract process in salesforce.
Task: Send extracted data to Dropzone nightly via SMS(Internal tool).
What steps do i need to perfrom in salesforce to do this?
I know to extract data from salesforce and save it in CSV format on desktop.
What do i do next to send this file to dropzone?
Develop a code? I heard this can be done using Data loader command line. Not sure where to start. Appreciate if someone can help me with detailed steps.
Thanks!  
Tom Hoban 2Tom Hoban 2
Take a look at this User Guide for our product FTPConnect.  We currently sell this product only to our BusinessConnect (another Equifax product) customers.  However, if you think this could be useful to you, I can probably find a way to sell you a license.

http://www.equifax.com/businessconnect/documents/FTPConnectUserGuide.pdf

With this tool, you can create batch jobs that can stream csv or other formats to Secure FTP (SFTP) sites.  The tool gives you several encryption options.  It also provides an API you can call from Apex to drop files onto an SFTP site in any creative way you want.

Note that the tool does not currently support unsecure FTP or FTPS.
 
jonghoon baejonghoon bae
Hi, all.
I also have same problem right below.
Can anybody know the right solutions?

Does anybody know how to connect SFDC with FTPS server?

Our goal is like below.

- All attached file should be stored into FTPS server with SSL.

- Files can't be stored in SFDC server, because of security issue.

- FTPS server is located on the inside of firewall and DMZ.

- We only need to connect FTPS server with SFDC.

- Our customer doesn't want to spend their money for FTP connection, and they have a FTP server now.

We tried to use trial version of many FTP apps from app exchange, such as "FTP ATTACHMENTS", "X files Pro", "Cloud files", but all are paid apps for our requests.

If somebody knows the proper app and how to do it, please give me a advice!

Thank you in advance!
Osvald MarkusOsvald Markus
To complete your requirement in transferring your data from Salesforce to FTP server via CSV file take a look at Skyvia (https://skyvia.com/data-integration/salesforce-data-loader). It`s is a no-coding integration client platform which needs minimal configuration and only a web browser to be accessed from anywhere. Uploading of data will be able by a click or you can schedule it on automatic execution
Adarsh.SharmaAdarsh.Sharma
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.

FTP API: https://ftp-api.herokuapp.com/
Blog Post: https://medium.com/@adarshsharma.jaipur/how-to-use-ftp-server-using-rest-api-8d1b3f88de0

Please let me know if you need any other information.