Javatpoint Logo
Javatpoint Logo

Java SFTP | File Transfer Using SFTP in Java JSCH

In digital word transferring file client to server and vice-versa is a typical process because the size of file may be large or may be un authorize access. So, it become necessary to protect the file and data from authorization. The SFTP ensures the security while transferring the file over the network. In this section, we will discuss how to transfer file from a remote server to the local system and vice versa using SSH File Transfer Protocol (SFTP) in Java.


SFTP stands for SSH File Transfer Protocol. It has replaced the legacy FTP protocol. It runs over the SSH protocol. It supports the full security and authentication functionality of SSH. In couple of years, it will also take over the FTPS protocol. There is no dedicated SFTP port; SFTP uses the normal SSH port i.e. 22.

Java SFTP | File Transfer Using SFTP in Java JSCH

Features of SFTP

  • It protects against password sniffing.
  • It avoids man-in-the-middle attack.
  • Protects the integrity of data using encryption and cryptographic hash function.
  • It authenticates both server and user.
Java SFTP | File Transfer Using SFTP in Java JSCH

Many SSH clients support SFTP:

  • Tectia SSH Client
  • WinSCP
  • FileZilla
  • PuTTY
  • Cyberduck

SFTP Libraries for Java Developers

  • JCraft JSch
  • SSHJ

Using JSch Library

JSch library provides the get() and put() method to transfer file between server and client. The put() method is used to transfer files from a local system to a remote server.

Add the jsch dependency to the pom.xml file.

It automatically downloads the jsch-0.1.55.jar file to the project directory.

We use put() method to transfer files from a local host to the server.

We use get() to download files from server to the local host.

Authenticate Password

Public and private keys authentication use Public Key Authentication with SSH

Let's see how to use keys in program.

let's see the following JSch example to transfer a file from the local system to a remote server, authenticate using an SSH password.



Note that the Jar file should be properly attached, else you will get error.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA