我设置了SFTP入站通道来轮询远程sftp服务器并将文件复制到本地目录。当它运行时,它给了我一个“权限被拒绝”#39;错误,但在日志文件中它正确提到文件名。因此它似乎能够正确列出远程路径的内容,但无法读取文件。
我还没有能够弄清楚访问问题究竟是什么。当我在测试服务器上摆弄它时,如果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
这是完整的异常跟踪。文件名在占位符&lt; FILENAME&gt;
中正确记录错误9860 --- [ask-scheduler-2] o.s.integration.handler.LoggingHandler:org.springframework.messaging.MessagingException:同步远程本地目录时出现问题 在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.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) 在org.springframework.integration.endpoint.AbstractPollingEndpoint $ 1.call(AbstractPollingEndpoint.java:149) 在org.springframework.integration.endpoint.AbstractPollingEndpoint $ 1.call(AbstractPollingEndpoint.java:146) 在org.springframework.integration.endpoint.AbstractPollingEndpoint $ Poller $ 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) at org.springframework.integration.endpoint.AbstractPollingEndpoint $ Poller.run(AbstractPollingEndpoint.java:292) 在org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 在org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471) 在java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) 在java.lang.Thread.run(Thread.java:744) 引起:org.springframework.messaging.MessagingException:从远程复制到本地目录时发生故障 在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:238) at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer $ 1.doInSession(AbstractInboundFileSynchronizer.java:177) at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer $ 1.doInSession(AbstractInboundFileSynchronizer.java:167) 在org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:302) 在org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:167) ......还有20个 引起:org.springframework.core.NestedIOException:无法读取文件&lt; FILENAME&gt ;;嵌套异常为3:权限被拒绝 在org.springframework.integration.sftp.session.SftpSession.read(SftpSession.java:132) at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:231) ......还有24个 造成:3:许可被拒绝 at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) 在com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1313) 在com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1266) 在org.springframework.integration.sftp.session.SftpSession.read(SftpSession.java:128) ......还有25个
如果有人能帮助我弄清楚我可能缺少的东西,我会很感激。