spring batch download sftp server file and insert to database sqlserver

I have an application in spring batch that downloads a file from an sftp server and then inserts it into a bd sqlserver my flow should be as follows:

1 - download the file

2 - read the file

3- process the file

4 inserts it into the database

to bring the file use the following code

in my class.config



    @Bean
    public SSHClient setupSshj() throws IOException {
        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");
        return client;

    }


    @Bean
    public SFTPClient whenDownloadFileUsingSshj_thenSuccess() throws IOException {
        SSHClient sshClient = setupSshj();
        SFTPClient sftpClient = sshClient.newSFTPClient();
        LOG.info("searching file....");
        sftpClient.get(PATH, LOCALDIR + "hola.csv ");
        LOG.info("file get successfully" + LOCALDIR + sftpClient);
        sftpClient.close();
        sshClient.disconnect();

        return sftpClient;

    }

I have an application in spring batch that downloads a file from an sftp server and then inserts it into a bd sqlserver my flow should be as follows:

1 - download the file

2 - read the file

3- process the file

4 inserts it into the database

to bring the file use the following code in my class .config

the problem is that when debugging the file does not return to me, so when the item reader is executed, it does not detect any file in the fileItemReader.setResource (new ClassPathResource ("hi.csv")); does not detect any files there until the execution of the code ends

downloaded file

console error

And when running the program again if it works correctly, what I need is to run the entire flow in a single program execution, This is my other part of the batch.config code:



    @Bean
    @Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
    public Pagare pagare() {
        return new Pagare();
    }

    @Bean
    @Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
    public ItemProcessor<Pagare, Pagare> itemProcessor() {
        return new PagareItemProcessor();
    }


    @Bean
    public BeanWrapperFieldSetMapper<Pagare> beanWrapperFieldSetMapper() {
        BeanWrapperFieldSetMapper<Pagare> fieldSetMapper = new BeanWrapperFieldSetMapper<>();
        fieldSetMapper.setPrototypeBeanName("pagare");
        return fieldSetMapper;
    }



    @Bean
    public FlatFileItemReader<Pagare> fileItemReader(BeanWrapperFieldSetMapper<Pagare> beanWrapperFieldSetMapper)  {

        FlatFileItemReader<Pagare> fileItemReader = new FlatFileItemReader<>();
        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<Pagare> defaultLineMapper = new DefaultLineMapper<>();
        defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
        defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
        fileItemReader.setLineMapper(defaultLineMapper);
        return fileItemReader;
    }

    @Bean
    public BeanPropertyItemSqlParameterSourceProvider<Pagare> beanPropertyItemSqlParameterSourceProvider() {
        return new BeanPropertyItemSqlParameterSourceProvider<>();
    }


    @Bean
    public ItemWriter<Pagare> JdbcBatchItemWriter(DataSource dataSource,
                                                  BeanPropertyItemSqlParameterSourceProvider<Pagare> sqlParameterSourceProvider) {
        JdbcBatchItemWriter<Pagare> jdbcBatchItemWriter = new JdbcBatchItemWriter<>();
        jdbcBatchItemWriter.setDataSource(dataSource);
        jdbcBatchItemWriter.setItemSqlParameterSourceProvider(sqlParameterSourceProvider);
        jdbcBatchItemWriter.setSql("insert into pagare(numeroPagare,numeroContrato,numeroOperacion,rutCliente,fechaOtorgamiento,marca,vehiculo,version,modelo,montoFinanciar,impuesto) values (:numeroPagare, :numeroContrato, :numeroOperacion, :rutCliente,:fechaOtorgamiento, :marca, :vehiculo, :version, :modelo,:montoFinanciar,:impuesto)");


        return jdbcBatchItemWriter;
    }

    @Bean
    public Job jobCsvMysql(JobBuilderFactory jobBuilderFactory, Step step) {
        return jobBuilderFactory.get("jobCsvMysql").incrementer(new RunIdIncrementer()).flow(step).end().build();
    }

    @Bean
    public Step step1(StepBuilderFactory stepBuilderFactory,
                      ItemReader<Pagare> reader, ItemWriter<Pagare> writer, ItemProcessor<Pagare, Pagare> processor) {
        return stepBuilderFactory.get("step1").<Pagare, Pagare>chunk(10)
                .reader(reader).processor(processor).writer(writer).build();


    }