SFTP In Coldfusion

I’ve just had to work on a task which creates a couple of CSV report files for an external business partner and then uploads them to their secure FTP server. In it’s original state it was using the Putty FTP client by writing a batch file and then having a scheduled task execute that batch file later (as the Coldfusion could not execute the batch file).

The problem with this, other than being long winded, was that there were no checks in place to verify whether the upload was successful or not. The only way this could be checked in the existing implementation was to manually log into the FTP server at a later time and make sure the file was there.

I decided to try see if Java had any way of handling SFTP and potentially writing a CFC wrapper for it myself, but luckily Michael Traher over at Social Points had already implemented a wrapper for JSch - Java Secure Channel.

It’s fairly straight forward to use, but could do with a bit more inline comments to help clarify the interface. One thing to note is if you need to use a private key to log into the SFTP server then make sure that it is in the OpenSSH format, which with PuttyGen was a really quick thing to do once I’d figured out the problem (by looking at through JSch mailing list archive.

So now the task creates the files and uploads them reporting the success or failure automatically.

Comments

There have been 3 comments so far, join the discussion.

1. Jasper - 4th Apr 2007 - 4:22 pm

Where can you get any support for the cfsftp.cfc? I’m running into lots of issues trying to implement this.

2. Dave - 4th Apr 2007 - 4:38 pm

Jasper:
I too had some problems with implementing this, I guess the best thing to do is post on the page for CFSFTP (http://www.socialpoints.com/blog/client/index.cfm/2006/3/25/coldfusion-sftp)

3. Tim Archer - 24th Apr 2007 - 12:32 pm

I also use Jsch in my production environment to send and retrieve data files with 3rd parties using SFTP. It works great. I did a little writeup on how to use it, complete with an example, at:
http://timarcher.com/?q=node/57

Leave a comment

No HTML please, only textile. For code please use [lang]...[/lang] tags (e.g. [html]...[/html] for HTML)