How to upload file to a server from Salesforce?

How do you setup an FTP server to do a custom action on file upload?

  • I want to connect 2 plugins to an FTP server 1. connect to "my db" to verify user access 2. Automatically hand off a task to another program once a user uploads a file (passing in the username, directory, filename as metadata) This can be done on *nix (Ubuntu or CentOS), but could ideally be tested on a Mac as well. Specifically, it seems that the FTP server of choice on Ubuntu is VSFTPD - so how do you configure it to execute a custom action on file upload?

  • Answer:

    Not sure if it's necessarily the best way, but one way (in Linux) is to use inotify(7). You can use it to subscribe to a directory, and (on receipt of the proper event, in this case, IN_CLOSE_WRITE or perhaps IN_MOVED_TO). This doesn't solve your first problem, but I bet that VSFTPD has a solution for that. Just make it so the user in question owns the uploaded file (easy, if you're authenticated them already). Then your inotify event handler can do whatever you need to the file, and the name and username will be properties of the file. In case you're not c-ish, look around for an inotify wrapper in your language of choice- there are many. The nice thing (or bad thing, depending on your viewpoint) about this solution is it decouples the handler from the ftp server.

Mike Lundy at Quora Visit the source

Was this solution helpful to you?

Other answers

This is fairly straightforward to do with Apache Mina FtpServer (http://mina.apache.org/ftpserver/). They have very nice authentication and file system abstractions, and a great FtpLet API which allows you to create your own custom actions on upload start/completion, and a few other triggers. It supports FTP and FTPS, but doesn't support SFTP (which is over an unrelated SSH protocol). Mina SSHD supports SFTP, but it's a young project which (as of June 2010) doesn't have the authentication/virtual FS abstraction/custom trigger abstraction yet, but the project is moving in that direction. I ended up using Mina FtpServer, and will likely change SSHD enough (and contribute back) to do what I need as well.

Toli Kuznets

Our product BrickFTP, which is a paid service, has a feature called "webhooks" that will send an HTTP request to your server whenever a new file is uploaded.  There's also a REST API that will allow you to set up users however you'd like.  We are also integrated with http://www.zapier.com/ which makes it easier for you to add your users and perform your actions.See the docs here:https://brickftp.com/docs/webhook-api/ https://brickftp.com/docs/rest-api/

Kevin Bombino

I feel duty-bound to say that you should try using SFTP instead of FTP, as it's less complex to secure and administer, and given the availability of encryption one should use it where possible. That said, if FTP is an absolute requirement, PureFTPd (http://www.pureftpd.org/project/pure-ftpd) can authenticate users against MySQL and PostrgreSQL, has a built-in mechanism for triggering shell or other scripts on upload, and is in my experience cleaner and less fiddly to set up than other FTP servers.

Igor Clark

I suggest too the generic inotify solution for uploads in an specific directory (you monitor single directories, not trees, if users can create directories and upload files there it may not be a solution). Some ftp servers (at least pureftpd, not sure about vsftpd) let you execute an script on file upload. If will be more targetted than using inotify (i.e. won't execute an action if you fiddle around that directory using other protocols or shell), but that functionality must be builtin in the server. Another alternative (not great, but could work for you) is to have a cron job that with the find command checks for new files there since the last run (and maybe check with i.e. lsof that the ftp server is not still writting on that file)

Gustavo Muslera

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.