java - 从sFtp服务器读取文件

  显示原文与译文双语对照的内容
0 0

我正在从sftp服务器读取文件并使用下面的Spring Batch 框架将该文件加载到数据库中,但这是我的错误

代码:


<bean id="cvsFileItemReaderMeta" class="org.springframework.batch.item.file.FlatFileItemReader">
 <!-- Read a csv file -->

 <property name="resource" value="ftp://scmuser:scmuser%40123@172.18.228.32:22/home/scmuser/CSV/Meta.csv"/>

错误:


org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
 at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:142)
 at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
 at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:115)
 at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
 at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:306)
 at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192)
 at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:137)
 at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
 at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
 at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152)
 at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)
 at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
 at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
 at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
 at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
 at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
 at com.tcs.ceg.iforesee.service.DataLoader.loadMetaMapping(DataLoader.java:127)
 at com.tcs.ceg.iforesee.service.UploadFile.uploadFile(UploadFile.java:77)
 at com.tcs.ceg.iforesee.service.UploadFile.main(UploadFile.java:22)
Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [ftp://username:password@hostname.com:22/home/scmuser/CSV/Meta.csv]
 at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:251)
 at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139)

时间: 原作者:

0 0

原因:java.lang. IllegalStateException: 输入资源必须存在( 读取器处于'严格'模式): URL [ ftp://username:password@hostname.com:22/home/scmuser/CSV/Meta.csv]

显然,资源不存在。 在尝试打开资源之前,或者在尝试使用 FlatFileItemReader#setStrict 或者通过 false/passing命令passing读模式时,必须确保资源存在。

在严格模式下,如果输入资源不存在,阅读器将在 AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) 上引发异常。

原作者:
0 0

要在 2步骤中划分 download+import,另一种方法是实现目标,并有更好的错误处理:

  1. 从FTP检索文件( 你可以使用 dedicer/退出状态。不完整的文件下载等处理文件)
  2. 从本地导入文件而不关心ftp传输错误( 例如,在数据导入中断的连接)
原作者:
...