SFTP file transfer using Java JSch

The Solution to SFTP file transfer using Java JSch is

The most trivial way to upload a file over SFTP with JSch is:

JSch jsch = new JSch();
Session session = jsch.getSession(user, host);

ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");

sftpChannel.put("C:/source/local/path/file.zip", "/target/remote/path/file.zip");

Similarly for a download:

sftpChannel.get("/source/remote/path/file.zip", "C:/target/local/path/file.zip");

You may need to deal with UnknownHostKey exception.

~ Answered on 2017-11-03 08:54:31

Most Viewed Questions: