How to download a file from SFTP Server using Zehon API ?

Zehon SFTP is a file-transfer component for Java language that provides secure file system access over an SSH channel using the SFTP protocol. It makes it easy to transfer files between your application and Unix/Windows SSH servers. All popular SSH/SFTP and proxy servers are supported.

Below is the feature list for Zehon SFTP

  • Stable and thoroughly tested code.
  • Batch file transfer – transfer a complete directory tree or a group of files corresponding to the specified mask.
  • All common firewalls and proxy servers are supported.
  • The API closely resembles Zehon FTP for Java – migrating existing applications from FTP to SFTP is easy.
  • Dedicated class for manipulating file and directory listings. Wildcards, regular expressions and symlinks supported.
  • Creating and deleting files and folders.
  • Resolving symlinks.
  • Setting and retrieving Unix file attributes.
  • Events and delegates for effortless integration with your applications.
  • Supports resuming file transfers after interruption.
  • Multiple simultaneous operations.
  • Progress event handler for monitoring uploads and downloads.
  • Error handling with Java exceptions.
  • Implements SFTP protocol version 3.
  • Includes SCP support through Scp class.
  • Compliant with RFC 4250-4254, 4256 and 4419.

Below java code shows how to download a file SFTP server using Zehon API –

Please download Zehon SFTP API from Zehon Website. Also please support Zehon by donating or clicking on an Ads on Zehon website.

* Created on Jul 4, 2012 Copyright(c) All Rights Reserved.
package com.kodehelp.zehon;
import com.zehon.FileTransferStatus;
import com.zehon.exception.FileTransferException;
import com.zehon.sftp.SFTP;
 * Created by Date: Jul 4, 2012
public class DownloadFileFromSFTP {
     * @param args
    public static void main(String[] args) {
        String host = ""; // Add your Host name or Host IP
        String username = "USERNAME"; // Your SFTP Server User Name
        String password = "PASSWORD"; // Your SFTP Server Password
        String SFTPFolder = "/export/"; // SFTp directory from where the file will be downloaded
        String localDownloadPath = "C:\\"; // folder path on local machine where the file will be downloaded
        String remoteFileName = "Sample.txt"; // Remote file name which will be downloaded
        try {
            int downloadStatus = SFTP.getFile(remoteFileName, SFTPFolder, host, username, password, localDownloadPath);
            if (FileTransferStatus.SUCCESS == downloadStatus) {
                System.out.println(remoteFileName + " got downloaded successfully to folder " + localDownloadPath);
            } else if (FileTransferStatus.FAILURE == downloadStatus) {
                System.out.println("Fail to download to folder " + localDownloadPath);
        } catch (FileTransferException e) {