我需要通过sftp连接到ftp服务器。我成功通过ftp和ftps与camel连接。
public static RouteBuilder getRouteBuilderSFTPS() {
return new RouteBuilder() {
public void configure() {
from("sftp://666.66.666.66:22/POLP-FROAKS?fileName=testMsg.txt&username=POLP-FROAKS&password=pass&strictHostKeyChecking=no&ciphers=blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,aes192-cbc,aes256-cbc").
to("file://target/test-reports667");
}
};
}
我得到respone org.apache.camel.component.file.GenericFileOperationFailedException:无法将目录更改为:POLP-FROAKS
完整日志:
16:25:32,758 INFO (main) [DefaultCamelContext] Apache Camel 2.9.2 (CamelContext: camel-1) started in 0.472 seconds
Apache Camel 2.9.2 (CamelContext: camel-1) started in 0.472 seconds
16:25:33,749 DEBUG (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpConsumer] Not connected/logged in, connecting to: sftp://POLP-FROAKS@216.66.216.10:22
Not connected/logged in, connecting to: sftp://POLP-FROAKS@216.66.216.10:22
16:25:33,753 DEBUG (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] Using ciphers: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,aes192-cbc,aes256-cbc
Using ciphers: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,aes192-cbc,aes256-cbc
16:25:33,764 DEBUG (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] Using StrickHostKeyChecking: no
Using StrickHostKeyChecking: no
16:25:33,769 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Connecting to 216.66.216.10 port 22
JSCH -> Connecting to 216.66.216.10 port 22
16:25:34,099 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Connection established
JSCH -> Connection established
16:25:34,476 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Remote version string: SSH-2.0-OpenSSH_4.3
JSCH -> Remote version string: SSH-2.0-OpenSSH_4.3
16:25:34,476 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Local version string: SSH-2.0-JSCH-0.1.48
JSCH -> Local version string: SSH-2.0-JSCH-0.1.48
16:25:34,476 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
JSCH -> CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
16:25:34,760 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> aes256-ctr is not available.
JSCH -> aes256-ctr is not available.
16:25:34,760 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> aes192-ctr is not available.
JSCH -> aes192-ctr is not available.
16:25:34,760 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> aes256-cbc is not available.
JSCH -> aes256-cbc is not available.
16:25:34,760 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> aes192-cbc is not available.
JSCH -> aes192-cbc is not available.
16:25:34,760 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> arcfour256 is not available.
JSCH -> arcfour256 is not available.
16:25:34,761 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> CheckKexes: diffie-hellman-group14-sha1
JSCH -> CheckKexes: diffie-hellman-group14-sha1
16:25:34,768 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> diffie-hellman-group14-sha1 is not available.
JSCH -> diffie-hellman-group14-sha1 is not available.
16:25:34,804 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_KEXINIT sent
JSCH -> SSH_MSG_KEXINIT sent
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_KEXINIT received
JSCH -> SSH_MSG_KEXINIT received
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
JSCH -> kex: server: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: ssh-rsa,ssh-dss,ssh-dss,ssh-rsa
JSCH -> kex: server: ssh-rsa,ssh-dss,ssh-dss,ssh-rsa
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
JSCH -> kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
JSCH -> kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
JSCH -> kex: server: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
JSCH -> kex: server: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: none,zlib@openssh.com
JSCH -> kex: server: none,zlib@openssh.com
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server: none,zlib@openssh.com
JSCH -> kex: server: none,zlib@openssh.com
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server:
JSCH -> kex: server:
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server:
JSCH -> kex: server:
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
JSCH -> kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
16:25:34,988 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: ssh-rsa,ssh-dss
JSCH -> kex: client: ssh-rsa,ssh-dss
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc
JSCH -> kex: client: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc
JSCH -> kex: client: blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
JSCH -> kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: none
JSCH -> kex: client: none
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client: none
JSCH -> kex: client: none
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client:
JSCH -> kex: client:
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client:
JSCH -> kex: client:
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: server->client blowfish-cbc hmac-md5 none
JSCH -> kex: server->client blowfish-cbc hmac-md5 none
16:25:34,989 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> kex: client->server blowfish-cbc hmac-md5 none
JSCH -> kex: client->server blowfish-cbc hmac-md5 none
16:25:35,015 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_KEXDH_INIT sent
JSCH -> SSH_MSG_KEXDH_INIT sent
16:25:35,015 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> expecting SSH_MSG_KEXDH_REPLY
JSCH -> expecting SSH_MSG_KEXDH_REPLY
16:25:35,451 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> ssh_rsa_verify: signature true
JSCH -> ssh_rsa_verify: signature true
16:25:35,455 WARN (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Permanently added '216.66.216.10' (RSA) to the list of known hosts.
JSCH -> Permanently added '216.66.216.10' (RSA) to the list of known hosts.
16:25:35,455 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_NEWKEYS sent
JSCH -> SSH_MSG_NEWKEYS sent
16:25:35,455 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_NEWKEYS received
JSCH -> SSH_MSG_NEWKEYS received
16:25:35,466 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_SERVICE_REQUEST sent
JSCH -> SSH_MSG_SERVICE_REQUEST sent
16:25:35,779 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> SSH_MSG_SERVICE_ACCEPT received
JSCH -> SSH_MSG_SERVICE_ACCEPT received
16:25:36,093 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Authentications that can continue: publickey,keyboard-interactive,password
JSCH -> Authentications that can continue: publickey,keyboard-interactive,password
16:25:36,094 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Next authentication method: publickey
JSCH -> Next authentication method: publickey
16:25:36,095 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Authentications that can continue: password
JSCH -> Authentications that can continue: password
16:25:36,095 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Next authentication method: password
JSCH -> Next authentication method: password
16:25:36,835 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Authentication succeeded (password).
JSCH -> Authentication succeeded (password).
16:25:37,932 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] Connected to sftp://POLP-FROAKS@216.66.216.10:22
Connected to sftp://POLP-FROAKS@216.66.216.10:22
16:25:37,932 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpConsumer] Connected and logged in to: sftp://POLP-FROAKS@216.66.216.10:22
Connected and logged in to: sftp://POLP-FROAKS@216.66.216.10:22
16:25:38,966 WARN (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [RemoteFilePollingConsumerPollStrategy] Trying to recover by disconnecting from remote server forcing a re-connect at next poll: sftp://POLP-FROAKS@216.66.216.10:22
Trying to recover by disconnecting from remote server forcing a re-connect at next poll: sftp://POLP-FROAKS@216.66.216.10:22
16:25:38,966 DEBUG (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpConsumer] Disconnecting from: sftp://POLP-FROAKS@216.66.216.10:22
Disconnecting from: sftp://POLP-FROAKS@216.66.216.10:22
16:25:38,966 INFO (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [SftpOperations] JSCH -> Disconnecting from 216.66.216.10 port 22
JSCH -> Disconnecting from 216.66.216.10 port 22
16:25:38,971 INFO (Connect thread 216.66.216.10 session) [SftpOperations] JSCH -> Caught an exception, leaving main loop due to socket closed
JSCH -> Caught an exception, leaving main loop due to socket closed
16:25:38,977 WARN (Camel (camel-1) thread #1 - sftp://216.66.216.10:22/POLP-FROAKS) [RemoteFilePollingConsumerPollStrategy] Consumer Consumer[sftp://216.66.216.10:22/POLP-FROAKS?ciphers=blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,aes192-cbc,aes256-cbc&fileName=testMsg.txt&password=******&strictHostKeyChecking=no&username=POLP-FROAKS] could not poll endpoint: Endpoint[sftp://216.66.216.10:22/POLP-FROAKS?ciphers=blowfish-cbc,aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,aes192-cbc,aes256-cbc&fileName=testMsg.txt&password=******&strictHostKeyChecking=no&username=POLP-FROAKS] caused by: Cannot change directory to: POLP-FROAKS
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot change directory to: POLP-FROAKS
at org.apache.camel.component.file.remote.SftpOperations.doChangeDirectory(SftpOperations.java:423)
at org.apache.camel.component.file.remote.SftpOperations.changeCurrentDirectory(SftpOperations.java:410)
at org.apache.camel.component.file.remote.SftpConsumer.doPollDirectory(SftpConsumer.java:78)
at org.apache.camel.component.file.remote.SftpConsumer.pollDirectory(SftpConsumer.java:50)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:100)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: 2: No such file
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2569)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2018)
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:316)
at org.apache.camel.component.file.remote.SftpOperations.doChangeDirectory(SftpOperations.java:421)
... 15 more
我有相同的代码,但没有骆驼,它的工作原理。骆驼版有什么问题?另外,我有点困惑为什么服务器没有问我私钥?
更新:
我试图添加私钥:
JSch.setLogger(new MyJschLogger());
JSch ssh = new JSch();
final byte[] privateKey = getPrivateKeyAsByteStream(privateKeyPath);
final byte[] passPrivateKey = "".getBytes();
//TODO DB: invalid private key. If not use private key than we can download file
ssh.addIdentity(username, privateKey, null, passPrivateKey);
session = ssh.getSession(username, server, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
final Vector files = sftp.ls(".");
Iterator itFiles = files.iterator();
while (itFiles.hasNext()) {
System.out.println("Index: " + itFiles.next());
}
sftp.get(remoteFile, localFile);
sftp.exit();
Key被引了,但我得到了错误:
com.jcraft.jsch.JSchException: invalid privatekey: POLP-FROAKS
at com.jcraft.jsch.IdentityFile.<init>(IdentityFile.java:302)
at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:135)
at com.jcraft.jsch.JSch.addIdentity(JSch.java:390)
at com.nxsystems.camel.Main.retrieveFileViaSFTP(Main.java:204)
at com.nxsystems.camel.Main.main(Main.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
使用PuTTY生成密钥。 FilleZilla通常接受钥匙。为什么????
更新: noup。问题不在于密钥。我使用puttyge.exe-&gt;转换将putty格式的密钥转换为openssh格式,JSCH成功接受了它。但旧错误&#34;无法将目录更改为...&#34;又回来了......
答案 0 :(得分:1)
最近在更改目录时遇到了同样的问题。解决方案是设置stepwise = false 来自documentation:
URI选项:stepwise,default = true:Camel 2.6:是否应该逐步遍历目录。逐步意味着它将一次CD一个目录。请在下面查看更多详情如果您不能使用此方法,可以禁用此功能
答案 1 :(得分:0)
您指定POLP-FROAKS作为FTP服务器的起始指示。因此,当Camel登录到FTP服务器时,它将在登录后执行CD POLP-FROAKS。如果您不应该更改为子目录,则从端点uri中删除它。例如,它只是
from("sftp://666.66.666.66:22/?xxx...