2

I am using Spring Batch 2. version.I have generated the csv file and able to save in csv format on local.

Now I want to generate the same file but it will be stored on SFTP server.

I had gone through some tutorial which generates file on sftp server but they are using spring integration with Spring Batch.

Is it possible to generate the file on SFTP server using Spring Batch only?

Below is itemReader bean defined::

<bean id="itemReader"
        class="org.springframework.batch.item.database.JdbcCursorItemReader"
        scope="step">
        <property name="dataSource" ref="dataSource" />
        <property name="sql"
            value="select u.ID, u.USER_LOGIN, u.PASSWORD, u.AGE from USERS u" />
        </property>
        <property name="rowMapper">
            <bean class="com.example.UserRowMapper" />
        </property>
    </bean>

ItemWriter Bean::

<bean id="flatFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
        <property name="resource" value="file:csv/user.csv" />

        <property name="appendAllowed" value="true" />
        <property name="lineAggregator">
            <bean           class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                <property name="delimiter" value="," />
                <property name="fieldExtractor">
                    <bean
                        class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                        <property name="names" value="name,age,id,password"/>
                        </bean>
        </property>
    </bean>
vinayakj
  • 5,591
  • 3
  • 28
  • 48
Vaibs
  • 1,546
  • 9
  • 31
  • I would recommend storing the file locally an then implement a tasklet which copies the file to an FTP server using library like ch.ethz.ssh2SFTPv3Client. – Hansjoerg Wingeier Dec 07 '16 at 06:59
  • Thank you for your suggestion. But I don't want to write new code or tasklet. I am looking for inbuilt functionality of spring batch which write file on SFTP server. – Vaibs Dec 07 '16 at 07:03
  • 2
    There is not such a thing. Also I have doubts if it is wise to do, because of instability problems and also latency and therefore performance issues (you don't want your job to pause everyime it waits for the ftp server to be ready to receive data). Moreover, often you have a jobcontrol system that takes care of copying files from one place to another, leaving the springbatch job just with the responsibility to produce the file and store it locally. Of course it depends on the circumstances. But generally I believe that it is better not to have a writer that writes directly to an FTP server. – Hansjoerg Wingeier Dec 07 '16 at 07:10

1 Answers1

0

You have to customize your writer class

LONGHORN007
  • 526
  • 9
  • 24