title: how to download file with spring batch tasklet and read for insert into DB
body: <p>I have created a Tasklet which connects to the sftp server and download the file but my code still does not work when passing to the itemreader since it tells me "Failed to initialize the reader" visualizing my IDE the file appears in the path at the end of the execution " Input resource must exist (reader is in 'strict' mode): class path resource [hi.csv] "</p>
  
  <p>my Tasklet class : </p>
  
  <pre><code>public class giveMeTheFile implements Tasklet {
  
  
      private static final String USERNAME = "seenisftp";
      private static final String HOST = "172.17.56.250";
      private static final String PASSWORD = "shenlong";
      private static final String PATH = "upload/test.csv";
      private static final String LOCALDIR = "src/main/resources/";
      private static final Logger LOG = LoggerFactory.getLogger(giveMeTheFile.class);
      private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(giveMeTheFile.class);
  
  
      @Override
      public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
  
  
          SSHClient client = new SSHClient();
          client.addHostKeyVerifier(new PromiscuousVerifier());
          LOG.info("Connecting to server..." + HOST);
          client.connect(HOST);
  
          LOG.info("verify.." + USERNAME);
          LOG.info("verify.." + PASSWORD);
          client.authPassword(USERNAME, PASSWORD);
          LOG.info("successful connection");
          SFTPClient sftpClient = client.newSFTPClient();
          LOG.info("searching file....");
          sftpClient.get(PATH, LOCALDIR + "hi.csv ");
          LOG.info("file get successfully" + LOCALDIR + sftpClient);
          sftpClient.close();
          client.disconnect();
  
  
          return RepeatStatus.FINISHED;
      }
  }
  
  
  </code></pre>
  
  <p>my item reader:</p>
  
  <pre><code>    @Bean
      public FlatFileItemReader&lt;Pagare&gt; fileItemReader(BeanWrapperFieldSetMapper&lt;Pagare&gt; beanWrapperFieldSetMapper)  {
  
          FlatFileItemReader&lt;Pagare&gt; fileItemReader = new FlatFileItemReader&lt;&gt;();
          fileItemReader.setLinesToSkip(1);
          fileItemReader.setResource(new ClassPathResource("hi.csv"));
          DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
          delimitedLineTokenizer.setNames("numeroPagare", "numeroContrato", "numeroOperacion", "rutCliente", "fechaOtorgamiento", "marca", "vehiculo", "version", "modelo", "montoFinanciar", "impuesto");
          DefaultLineMapper&lt;Pagare&gt; defaultLineMapper = new DefaultLineMapper&lt;&gt;();
          defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
          defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
          fileItemReader.setLineMapper(defaultLineMapper);
          return fileItemReader;
      }
  
  </code></pre>
  
  <p>my step that calls the tasklet:</p>
  
  <pre><code>   @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .tasklet(new giveMeTheFile())
                  .build();
      }
  
  </code></pre>
  
  <p>my job that calls steps:</p>
  
  <pre><code>    public Step step4(ItemReader&lt;Pagare&gt; reader, ItemWriter&lt;Pagare&gt; writer, ItemProcessor&lt;Pagare, Pagare&gt; processor) {
          return stepBuilderFactory.get("step4")
                  .&lt;Pagare, Pagare&gt; chunk(10)
                  .reader(reader)
                  .faultTolerant()
                  .skipLimit(1)
                  .skip(FlatFileParseException.class)
                  .processor(processor)
                  .writer(writer)
                  .build();
      }
  </code></pre>
  
  <p>I do not understand what I am doing wrong if I did the tasklet with the connection and download of the file ... because the download is not complete at the end of the tasklet? According to the official documentation the tasklet is used for tasks before the execution</p>