java - Spring SFTP 连接 - 从 SFTP 服务器获取文件

标签 java spring spring-integration sftp

我是 Spring 的新手。我正在使用 spring 从远程服务器获取文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:sftp="http://www.springframework.org/schema/integration/sftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/sftp
    http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.2.xsd">

<bean id="sftpSessionFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="xxxxxxxx" />
    <property name="user" value="wildfly" />
    <property name="password" value="w!ldfly" />
    <property name="port" value="22" />
</bean>

<int:channel id="sftpChannel" />

<sftp:inbound-channel-adapter id="triggerFtpInBound" auto-create-local-directory="true"
    local-directory="/tmp/test" filename-pattern="*" channel="sftpChannel"
    session-factory="sftpSessionFactory" remote-directory="/home/wildfly" delete-remote-files="true">
    <int:poller cron="1/10 * * * * *" max-messages-per-poll="1" />
</sftp:inbound-channel-adapter>

我正在使用以下代码。

ApplicationContext context = new ClassPathXmlApplicationContext("spring/config/spring-sftp.xml");

当我运行它时,我没有收到任何错误,但我也没有复制任何文件。请让我知道我的代码中的错误。提前致谢。

最佳答案

仅查看静态配置很难进行调试。

第一步是打开 org.springframework.integration 的 DEBUG 日志记录并查看发生了什么。

如果你无法从日志中弄清楚,请将其发布;如果这里太大,请使用 github gist、pastebin 或类似的。

Spring Integration 在幕后使用 jsch;您可以按照描述启用其日志记录in the reference manual .

关于java - Spring SFTP 连接 - 从 SFTP 服务器获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34100666/

相关文章:

java - 如何在 Spring Security 中的子域之间共享 session

java - Spring ftp 集成。处理后删除文件

java - 使用 Spring 集成执行器 channel 时超出 GC 限制

java - 如何从 ContentValues 获取 key ?

java - 错误: Could not find or load main class Swagger Codegen

spring - View 状态内 webflow 中的 If & Else 语句

java - Spring 原型(prototype)作用域行为

java - JMS - CorrelationID 与 ReplyTo

java - Jaxb2Marshaller 无法以线程安全的方式解码非 XmlRoot 元素

java - 使用 ifelse 语句修改 JSTL 中的代码