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

  • SEARCH
  • Home
  • 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 6250033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:20:51+00:00 2026-05-24T13:20:51+00:00

I have to read a bunch of .CSV files with dynamic file names from

  • 0

I have to read a bunch of .CSV files with dynamic file names from a SFTP server. These files get generated every 15 minutes.

I am using JSch’s ChannelSftp, but there is no method which would give the exact filenames. I only see an .ls() method. This gives a Vector e.g.

[drwxr-xr-x    2 2019     2019          144 Aug  9 22:29 .,
 drwx------    6 2019     2019          176 Aug 27  2009 ..,
 -rw-r--r--    1 2019     2019          121 Aug  9 21:03 data_task1_2011_TEST.csv,
 -rw-r--r--    1 2019     2019          121 Aug  9 20:57 data_task1_20110809210007.csv]

Is there a simple way to read all the files in a directory and copy them to another location?

This code works for copying a single file:

JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp)channel;
channelSftp.cd(SFTPWORKINGDIR);
channelSftp.get("data_task1_20110809210007.csv","data_task1_20110809210007.csv");
  • 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-05-24T13:20:52+00:00Added an answer on May 24, 2026 at 1:20 pm

    The ls method is the one you need. It returns a vector of LsEntry objects, each of which you can ask about its name.

    So, after your channelSftp.cd(SFTPWORKINGDIR);, you could do the following:

    Vector<ChannelSftp.LsEntry> list = channelSftp.ls("*.cvs");
    for(ChannelSftp.LsEntry entry : list) {
        channelSftp.get(entry.getFilename(), destinationPath + entry.getFilename());
    }
    

    (This assumes destinationPath is a local directory name ending with / (or \ in Windows).)

    Of course, if you don’t want to download the same files again after 15 minutes, you might want to have a list of the local files, to compare them (use a HashSet or similar), or delete them from the server.

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

Sidebar

Related Questions

I have a bunch of csv files. Each has data from a different period:
I need to read a bunch of binary files from a Java script running
I loaded a bunch of CSV files into R. I have questions about how
I have a bunch of CSV files. In some of them, missing data are
So I have a CSV file with a bunch on IP's in it: 192.168.0.1,192.168.0.2,192.168.0.3,192.168.0.4,192.168.0.5,192.168.0.6,192.168.0.7,192.168.0.8,192.168.0.9,192.168.0.10
I have read a bunch of forums on this but none have solved my
I have a process where I read in a bunch of strings in ISO
I read in a csv file by using a while loop: while (($data =
I've been asked to output a CSV file from a view in MySQL. The
I have to read a pdf file which contains a table with several columns.

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.