【发布时间】:2018-01-04 02:54:21
【问题描述】:
我正在尝试从 SFTP 服务器位置下载文件,但日志看起来不错,最后没有从服务器下载到本地。也没有错误出现。请提前提供您的输入。
可用的 SFTP 文件:
[root@rsysftp test1]# ls /tmp/files/test1
test1.txt test2.txt test3.txt test4.txt
路由器:
@Component
public class SampleCamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
getContext().getShutdownStrategy().setTimeout(10);
from("sftp://ftpuser1@some.ip.value.here/tmp/files/test1?password=pass")
.to("file:C:/out")
.log("Downloaded file ${file:name} complete.");
}
}
日志:
o.a.camel.spring.SpringCamelContext : Route: route1 started and consuming from: sftp://ftpuser1@some.ip.value.here/tmp/files/test1/test1.txt?password=xxxxxx
o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started.
o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.1 (CamelContext: SampleCamel) started in 30.871 seconds
s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
c.camel.examples.SampleCamelApplication : Started SampleCamelApplication in 37.837 seconds (JVM running for 38.891)
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream-starter</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-springboot</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
Windows 版本?您是否尝试过使用其他文件,例如
C:/Test/out? -
感谢您的回复,Windows7 以及更改位置的行为会有何不同?
-
是的。有时可能存在权限问题。您是否检查了您使用的路径中是否有任何文件,即
C:\out?并且,尝试使用其他路径并再次测试。 -
我试图包含 File file = new File("C:/Users/a591470/Downloads/test/test10.txt");文件.createNewFile();代码也是路由器的一部分,但这会创建文件,因此不存在权限问题。
-
好。可以尝试在控制台打印下载的内容吗?
标签: java spring-boot apache-camel sftp