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.