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

Failure to remove a file using an outbound-gateway

我正在尝试使用 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)

为了完整起见,这是我发送到出站网关的内容:

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

干杯,杰斯

Failed to remove file: 4: Failure

不幸的是,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 请求的地方。