Over a million developers have joined DZone.

Groovy and JSch : SFTP transferring files

DZone's Guide to

Groovy and JSch : SFTP transferring files

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

This is a simple example of how to transfer a file using Groovy, JSch, and SFTP. 

@Grab(group='com.jcraft', module='jsch', version='0.1.46')
import com.jcraft.jsch.*

java.util.Properties config = new java.util.Properties()
config.put "StrictHostKeyChecking", "no"

JSch ssh = new JSch()
Session sess = ssh.getSession "user", "server.domain.com", 22
sess.with {
setConfig config
setPassword "somecomplicatedpassword"
Channel chan = openChannel "sftp"

ChannelSftp sftp = (ChannelSftp) chan;
def sessionsFile = new File('c:/important_document.doc')
sessionsFile.withInputStream { istream -> sftp.put(istream, "/home/brippe/Documents/important_document.doc") }

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}