Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:22:04+00:00 2026-06-15T10:22:04+00:00

I am using jsch to download files from server, my code below. public static

  • 0

I am using jsch to download files from server, my code below.

public static void downloadFile(TpcCredentialsDTO dto) {
        logger.trace("Entering downloadFile() method");
        
    Session session = null;
    Channel channel = null;
    ChannelSftp channelSftp = null;
    boolean success = false;
    
    try {
        JSch jsch = new JSch();
        session = jsch.getSession(dto.getUsername(), dto.getHost(),
                dto.getPort());
        session.setPassword(dto.getPassword());

        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();
        logger.info("Connected to " + dto.getHost() + ".");
        
        channel = session.openChannel("sftp");
        channel.connect();
        channelSftp = (ChannelSftp) channel;
        
        List<String> filesToDownload = getFilesToDownload(dto,channelSftp);
        
        if (!filesToDownload.isEmpty()) {
            for (String fileDownloadName : filesToDownload) {
                success = false;
                OutputStream output = new FileOutputStream(
                    "C:\Download\BLT_03112012");
                
                channelSftp.get("BLT_03112012",output);
                success = true;
                if (success)
                    logger.info(ServerConstants.DOWNLOAD_SUCCESS_MSG
                                    + fileDownloadName);
                output.close();
            }

        }else {
            logger.info(ServerConstants.NO_FILES_TO_DOWNLOAD
                    + ServerUtils.getDateTime());
            success = true;
        }
        
    } catch (JSchException ex) {
        logger.error( ServerConstants.SFTP_REFUSED_CONNECTION, ex);
    } catch (SftpException ex) {
        logger.error(ServerConstants.FILE_DOWNLOAD_FAILED, ex);
    } catch (IOException ex) {
        logger.error(ServerConstants.FILE_NOT_FOUND, ex);
    }catch (Exception ex) {
        logger.error(ServerConstants.ERROR, ex);
    }finally {
        if (channelSftp.isConnected()) {
            try {
                session.disconnect();
                channel.disconnect();
                channelSftp.quit();
                logger.info( ServerConstants.FTP_DISCONNECT);
            } catch (Exception ioe) {
                logger.error(ServerConstants.FTP_NOT_DISCONNECT, ioe);
            }
        }
    }
    logger.trace("Exiting downloadFile() method");
}

The line sftpChannel.get(filename, outputstream) is throwing an error.

  2: File not found
      at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2629)
      at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:977)
      at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:946)
      at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:924)
      at za.co.tpc.sftpserver.SftpConnection.downloadFile(SftpConnection.java:72)
      at za.co.tpc.server.execute.FtpMtn.main(FtpMtn.java:44)

The same code does download Text Document file types but fails for ‘File’ filetype

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:22:05+00:00Added an answer on June 15, 2026 at 10:22 am

    Try using paths instead of stream:

    String destPath = "filename.txt";        
    
    if (!filesToDownload.isEmpty()) {
        for (String fileDownloadName : filesToDownload) {
            success = false;
            sftpChannel.get(fileDownloadName , destPath);  
    

    If you wanna use file and streams check this example:
    http://kodehelp.com/java-program-for-downloading-file-from-sftp-server/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSch to get files from an SFTP server, but I'm trying to
I am using JSch library to upload file from sdcard to SFTP server but
The applet will download file from a SFTP server. JSch libraries are used to
i am using jsch to get ssh output from a local ssh server. When
I'm using Jsch 0.1.44 to scp a file from one host to another. The
I'm looking at setting up public key client and server authentication for SFTP using
I am using a jsch library to connect to a server using ssh connection.
I'm currently using JSch as the library for connecting to my remote server. In
I am using Jsch to connect sshd server and I am new in this
Using SQL Server 2008 R2 we are looking for a way to select the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.