我有一个SFTP入站通道设置为轮询远程sftp服务器并将文件复制到本地目录 . 当它运行时,它给我一个'权限被拒绝'错误,但在日志文件中它正确提到了文件名 . 所以它似乎能够正确列出远程路径的内容,但无法读取文件 .

我无法弄清楚访问问题究竟是什么 . 当我在测试服务器上摆弄它时,如果sftp用户在远程目录上至少具有r-x访问权限,但我无法访问文件本身,我可以看到我会遇到同样的问题 . 但是,在我遇到问题的实时服务器上,用户确实具有此必需的访问级别 .

运行sftp命令会复制文件而不会出现任何问题:

/usr/bin/sftp -2 -i KEYFILE USER@SERVER:REMOTEDIR/FILEPATTERN* LOCALDIR

以下是我在Spring Integration配置中使用SFTP通道的方法:

<int:poller default="true" fixed-rate="${fixed.rate}" />

<bean id="sftpClientFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="${sftp.inbound.channel.host}" />
    <property name="port" value="${sftp.inbound.channel.availableServerPort}" />
    <property name="user" value="${sftp.inbound.channel.userid}" />
    <property name="password" value="${sftp.inbound.channel.password}" />
    <property name="privateKey" value="file:///${sftp.inbound.channel.server.key}"></property>
</bean>

<int-sftp:inbound-channel-adapter id="sftpInbound"
    channel="sftpChannel" session-factory="sftpClientFactory"
    filename-pattern="${input.file.format}" auto-create-local-directory="true"
    delete-remote-files="false" remote-directory="${sftp.inbound.channel.remote.directory}"
    local-directory="${sftp.inbound.channel.local.directory}">
</int-sftp:inbound-channel-adapter>

<int:channel id="sftpChannel">
    <int:queue />
</int:channel>

该项目使用的是Spring Integration版本4.0.4-RELEASE

这是完整的异常跟踪 . 文件名在占位符<FILENAME>中正确记录

9860 ERROR --- [问调度-2] osintegration.handler.LoggingHandler:同时在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer同步远程到本地目录发生问题:org.springframework.messaging.MessagingException .synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:209)org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.receive(AbstractInboundFileSynchronizingMessageSource.java:167)org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:124 )org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:192)org.springframework.integration.endpoint.AbstractPollingEndpoint.access $ 000(AbstractPollingEndpoint.java:55)at org.springframework.integration.endpoint.AbstractPollingEndpoint org.springframework.i上的$ 1.call(AbstractPollingEndpoint.java:149) ntegration.endpoint.AbstractPollingEndpoint $ 1.call(AbstractPollingEndpoint.java:146)在org.springframework.integration.endpoint.AbstractPollingEndpoint $轮询$ 1.run(AbstractPollingEndpoint.java:298)在org.springframework.integration.util.ErrorHandlingTaskExecutor $ 1.run (ErrorHandlingTaskExecutor.java:52)在org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)在org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)在org.springframework . deploy.endpoint.AbstractPollingEndpoint $ Poller.run(AbstractPollingEndpoint.java:292)org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable . java:81)at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)at java.util.concurrent.FutureTask.run(FutureTask.java:262)at java.util.concurrent.Scheduled ThreadPoolExecutor $ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:178)java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)at at Java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)at java.lang.Thread.run(Thread.java:744)引起:org.springframework.messaging.MessagingException:从远程复制时发生故障到org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:238)的本地目录org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer $ 1.doInSession(AbstractInboundFileSynchronizer.java:177)在org.spring的org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer $ 1.doInSession(AbstractInboundFileSynchronizer.java:167) ORG:framework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:302)在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:167)...... 20多所致.springframework.core.NestedIOException:无法读取文件<FILENAME>;嵌套异常是3:权限在org.springframework.integration.sftp.session.SftpSession.read(SftpSession.java:132)在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:231否认)... 24更多引起:3:com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)com的com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1313)中的权限被拒绝 . jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1266)atorg.springframework.integration.sftp.session.SftpSession.read(SftpSession.java:128)... 25更多

如果有人能帮助我弄清楚我可能缺少什么,我将不胜感激 .