title: Unable to fetch list of files using jsch in java, to remote server's directory
body: <p>I am trying to populate files to a remote server using jsch library. The directory structure is like '/home/myname/batch_run_dt=20180706/batchid=P20180706001/* '</p>
  
  <p>so the base directory, <strong><em>batch_run_dt</em></strong>, contains multiple sub directories (batchid=P20180706*), and further those have files. The structure is to be maintained in the similar manner in remote server. I am using below piece of code to implement this functionality.</p>
  
  <pre><code>    public class Runner{
      public static void main(String[] args) throws FileNotFoundException, IOException, SQLException, JSchException {
      Date todaydate = new Date();
      Calendar cal = Calendar.getInstance();
      cal.setTime(todaydate);
      cal.add(Calendar.DAY_OF_MONTH,-1);
  
  
   SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
  
   String date = ft.format(cal.getTime());
      logger.info("date :: " + date);
      // starting the process
  
          String partition = "batch_run_dt=" + date;
          getData(partition);
  }    
   public static void getData(String partition)       throws JSchException {
      logger.info("Starting download data ");
      // get the destination location
      String destLoc = "/home/myname/" + partition;
  
      // get source location from data needs to import through sftp
      String srcLoc = "/home/myname/" + partition;
  
      download(partition, prop, destLoc, srcLoc);
      logger.info("Finished download prov data ");
  }
  
  public static void download(String partition, Properties prop, String destLoc, String srcLoc) throws JSchException {
  
      // creaating a sesssion for jsch
      Session session = NonProdRunner.createjschsession("username",
              "password", "host");
      // creating a channel from session
      Channel channel = session.openChannel("sftp");
      channel.connect();
      // creating sftp channel to connect
      ChannelSftp channelSftp = (ChannelSftp) channel;
  
      // create file object
      File dir = new File(destLoc);
  
      // check if file exists if exists, means we already have data
      // else create directory structure
      if (!dir.exists()) {
          dir.mkdirs();
      } else {
          logger.error("File already exist");
          new Exception("Destination already Exists");
      }
  
      logger.info("Created destination folders");
  
      // get all the files
      mget(channelSftp, srcLoc, destLoc);
      // close connection and session
      channelSftp.exit();
      session.disconnect();
      System.out.println("session disconnected");
  
  }
  
  private static Session createjschsession(String uname, String pwd, String host) throws JSchException {
      JSch jsch = new JSch();
      Session session = jsch.getSession(uname, host);
      session.setPassword(pwd);
      java.util.Properties config = new java.util.Properties();
      config.put("StrictHostKeyChecking", "no");
      session.setConfig(config);
      logger.info("Connecting Session");
      session.connect();
      logger.info("Connected Session");
      return session;
  
  }
  
  private static void mget(ChannelSftp channelSftp, String srcLoc, String destLoc) {
      try {
          // Setting the folder location of the external system as
          // configured
          // to download the file from
          logger.info("src loation :: " + srcLoc);
          channelSftp.cd(srcLoc);
          channelSftp.lcd(destLoc);
          logger.info("folder changed");
          Vector&lt;LsEntry&gt; dirlist = channelSftp.ls("*");
          logger.info("Got list of remote files");
          for (LsEntry entry : dirlist) {
  
              Vector&lt;LsEntry&gt; batchID = channelSftp.ls("*");
  
  
              for (LsEntry batchEntry : batchID) {
  
                  String filename = batchEntry.getFilename();
                  logger.info("Loading BatchID: " + filename);
  
                  File dir = new File(destLoc+"/"+filename);
                  dir.mkdirs();
  
                  logger.info(destLoc+"/"+filename);
                  System.out.println(destLoc+"/"+filename);
  
                  channelSftp.cd(filename);
  
                  logger.info("Entered into: " + filename);
  
                  Vector&lt;LsEntry&gt; files = channelSftp.ls(srcLoc+"/"+filename+"/*");
                  for (LsEntry file: files) {
  
                      logger.info(file.getFilename());
  
                      String partFiles = file.getFilename();
  
                      channelSftp.get(partFiles, destLoc+"/"+filename);//.get(partFiles, partFiles);
  
                  }
              }
  
          }
          logger.info("File copy done");
  
      } catch (SftpException sftpException) {
          logger.error("Exception in sftp: " + sftpException.getMessage());
          System.exit(-1);
      }
  }
  </code></pre>
  
  <p>} </p>
  
  <p>but I am getting an error after the very first sub-folder is loaded that <strong><em>Exception in sftp: No such file</em></strong> . Not sure what I am missing here, Please help in resolving this.</p>