无法使用出站网关删除文件

时间:2015-06-17 13:45:46

标签: spring-integration jsch

我尝试使用sftp出站网关删除远程sftp上的特定日志文件。

<int-sftp:outbound-gateway id="removeSourceGateway"
                               session-factory="sftpCachingSessionFactory" 
                               reply-channel="outputChannel"
                               request-channel="afterSuccessBackupChannel"
                               requires-reply="false"
                               command="ls"
                               expression="'/export/logs/'"
                               remote-directory="${sftp.remote.dir}">
</int-sftp:outbound-gateway>

如果我在上面的配置中执行LS或PUT命令,那么我得到预期的内容 - 请参阅下面的LS消息示例。但每当我尝试运行RM命令时,我都会得到一条相当神秘的错误信息。

GenericMessage [payload=[FileInfo [isDirectory=false, isLink=false, Size=2348, ModifiedTime=Wed Jun 17 15:21:13 CEST 2015, Filename=sdk.20150601003030.log, RemoteDirectory=/export/logs/, Permissions=-rw-rw-rw-]]

为了给这个问题增加更多的误解,每当我使用WinSCP连接到SFTP并使用完全相同的帐户时,我就能完全删除远程文件!

错误消息:

2015-06-17 15:19:56 INFO  jsch:52 - SSH_MSG_NEWKEYS received
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - SSH_MSG_SERVICE_REQUEST sent
2015-06-17 15:19:56 INFO  jsch:52 - SSH_MSG_SERVICE_REQUEST sent
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - SSH_MSG_SERVICE_ACCEPT received
2015-06-17 15:19:56 INFO  jsch:52 - SSH_MSG_SERVICE_ACCEPT received
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - Authentications that can continue: password
2015-06-17 15:19:56 INFO  jsch:52 - Authentications that can continue: password
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - Next authentication method: password
2015-06-17 15:19:56 INFO  jsch:52 - Next authentication method: password
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - Authentication succeeded (password).
2015-06-17 15:19:56 INFO  jsch:52 - Authentication succeeded (password).
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 DEBUG SimplePool:190 - Obtained new org.springframework.integration.sftp.session.SftpSession@3b63f280.
2015-06-17 15:19:56 DEBUG SimplePool:190 - Obtained new org.springframework.integration.sftp.session.SftpSession@3b63f280.
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 INFO  jsch:52 - Disconnecting from *.*.*.* port 22
2015-06-17 15:19:56 INFO  jsch:52 - Disconnecting from *.*.*.* port 22
2015-06-17 15:19:56 INFO  stdout:71 - 2015-06-17 15:19:56 DEBUG SimplePool:221 - Releasing org.springframework.integration.sftp.session.SftpSession@3b63f280 back to the pool
2015-06-17 15:19:56 DEBUG SimplePool:221 - Releasing org.springframework.integration.sftp.session.SftpSession@3b63f280 back to the pool
2015-06-17 15:19:57 INFO  stdout:71 - 2015-06-17 15:19:57 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:19:57 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:19:57 INFO  stdout:71 - 2015-06-17 15:19:57 DEBUG DirectChannel:277 - preSend on channel 'outputChannel', message: ErrorMessage [payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 4: Failure, headers={timestamp=1434547197002, id=18ca7961-f5f0-de0d-03f2-04909dbcdebc}]
2015-06-17 15:19:57 DEBUG DirectChannel:277 - preSend on channel 'outputChannel', message: ErrorMessage [payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 4: Failure, headers={timestamp=1434547197002, id=18ca7961-f5f0-de0d-03f2-04909dbcdebc}]
2015-06-17 15:19:57 INFO  stdout:71 - 2015-06-17 15:19:57 DEBUG CharacterStreamWritingMessageHandler:72 - org.springframework.integration.stream.CharacterStreamWritingMessageHandler#0 received message: ErrorMessage [payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 4: Failure, headers={timestamp=1434547197002, id=18ca7961-f5f0-de0d-03f2-04909dbcdebc}]
2015-06-17 15:19:57 DEBUG CharacterStreamWritingMessageHandler:72 - org.springframework.integration.stream.CharacterStreamWritingMessageHandler#0 received message: ErrorMessage [payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 4: Failure, headers={timestamp=1434547197002, id=18ca7961-f5f0-de0d-03f2-04909dbcdebc}]
2015-06-17 15:19:57 INFO  stdout:71 - org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 4: Failure
2015-06-17 15:19:57 INFO  stdout:71 -   at org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice.evaluateFailureExpression(ExpressionEvaluatingRequestHandlerAdvice.java:185)
2015-06-17 15:19:57 INFO  stdout:71 -   at org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice.doInvoke(ExpressionEvaluatingRequestHandlerAdvice.java:143)
2015-06-17 15:19:57 INFO  stdout:71 -   at org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice.invoke(AbstractRequestHandlerAdvice.java:69)
2015-06-17 15:19:57 INFO  stdout:71 -   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
2015-06-17 15:19:57 INFO  stdout:71 -   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
2015-06-17 15:19:57 INFO  stdout:71 -   at com.sun.proxy.$Proxy62.handleMessage(Unknown Source)

对于completness,这里是我发送到我的出站网关的地方:

2015-06-17 15:38:15 INFO  FtpSession:126 - File has been successfully transfered to: /Private/logs/2015-06/sdk.20150601003030.log
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 DEBUG SimplePool:221 - Releasing org.springframework.integration.ftp.session.FtpSession@2718fca1 back to the pool
2015-06-17 15:38:15 DEBUG SimplePool:221 - Releasing org.springframework.integration.ftp.session.FtpSession@2718fca1 back to the pool
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:38:15 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 DEBUG DirectChannel:277 - preSend on channel 'afterSuccessBackupChannel', message: AdviceMessage [payload=/data/logs/live-test/sdk/sdk.20150601003030.log, headers={timestamp=1434548295753, id=17408be9-8acd-0325-b726-e87c81cafcc8}]
2015-06-17 15:38:15 DEBUG DirectChannel:277 - preSend on channel 'afterSuccessBackupChannel', message: AdviceMessage [payload=/data/logs/live-test/sdk/sdk.20150601003030.log, headers={timestamp=1434548295753, id=17408be9-8acd-0325-b726-e87c81cafcc8}]
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 DEBUG SftpOutboundGateway:72 - org.springframework.integration.sftp.gateway.SftpOutboundGateway#0 received message: AdviceMessage [payload=/data/logs/live-test/sdk/sdk.20150601003030.log, headers={timestamp=1434548295753, id=17408be9-8acd-0325-b726-e87c81cafcc8}]
2015-06-17 15:38:15 DEBUG SftpOutboundGateway:72 - org.springframework.integration.sftp.gateway.SftpOutboundGateway#0 received message: AdviceMessage [payload=/data/logs/live-test/sdk/sdk.20150601003030.log, headers={timestamp=1434548295753, id=17408be9-8acd-0325-b726-e87c81cafcc8}]
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:38:15 DEBUG DefaultListableBeanFactory:248 - Returning cached instance of singleton bean 'integrationEvaluationContext'
2015-06-17 15:38:15 INFO  stdout:71 - 2015-06-17 15:38:15 INFO  jsch:52 - Connecting to *.*.*.* port 22

干杯,Jes

1 个答案:

答案 0 :(得分:1)

  

无法删除文件:4:失败

不幸的是,com.jcraft.jsch库(用于sftp)的异常在这种情况下有点神秘(4: Failure)......

4表示:

SSH_FX_FAILURE
  is a generic catch-all error message; it should be returned if an
  error occurs for which there is no more specific error code
  defined.

...深入研究jsch代码,在我看来这个状态是由服务器返回的。服务器日志中有什么内容吗?

如果没有,您可能必须使用wireshark或类似的东西来弄清楚服务器对rm请求不感兴趣。