title: Downloading Files from SFTP using jsch
body: <p>I am using JSCH to download files from SFTP server.
  I am using single session, with multiple channels to download files from different folders located in SFTP.
  For this downloading process I have a set of scheduled jobs. Each job will:</p>
  
  <ol>
  <li>open a new channel (<code>ChannelSftp</code>) everytime. channel name : sftp</li>
  <li>uses method <code>ChannelSftp.ls()</code> to get the size of total number of files to download</li>
  <li>If size(Vector) is greater than zero then uses <code>ChannelSftp.get(remotedir/'*.*', localdir)</code> to download all the files</li>
  <li>finally closes the opened channel.</li>
  </ol>
  
  <p>During the above process most of the times I am getting File Not Found or No Such File Exceptions and not downloading some files.</p>
  
  <p>Can anyone please suggest me why it will happen. What may be the cause. How to resolve this problem</p>
  
  <p>below is the code I am using:</p>
  
  <pre class="lang-java prettyprint-override"><code>ChannelSftp channelSftp = null;
  
  try {
      channelSftp = getChannelConnectionUtil().openChannel(); //SFTPConnection.getSession().openChannel("sftp");  
  
      @SuppressWarnings("rawtypes")
      Vector numOfFiles = channelSftp.ls(ftpDir+"/*.*");
  
      if(numOfFiles.size() &gt; 0){
          channelSftp.get(ftpDir+"/*.*",localDir); // Here I am getting error
      }
  }  catch (Exception e) {
      e.printStackTrace();
  } finally {
      getChannelConnectionUtil().disconnectChannel(channelSftp);
  }
  </code></pre>