Yesterday I introduced how I send files via FTP and SFTP from my java applications. In that post I showed you how to use the Jakarta Commons Net package to FTP files. Today I will show you how to use the JSch (Java Secure Channel) library to do SFTP transfers.
Part 2 of 2 – Using JSch (Java Secure Channel)
First off, what exactly is JSch? Well, the JCraft team describes it says that “JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs.” Personally, I’ve only used it to SFTP files, and have not yet used any of its other features.
To use JSch, you’ll first want to download the appropriate libraries from JCraft. Click here to be taken to the JSch homepage and download the jsch library. For my example I downloaded the jsch-0.1.32.jar file directly from their site. Once you download the file, put it in your classpath.
Now just grab the code I present below and go to town. Like the Commons Net library, the JSch library is extremely easy to use!
continue reading…