spring-integration - spring integration - SFTP 确保上传成功
问题描述
我们如何确定文件是否成功上传到 SFTP 服务器。我想确保 SFTP 上传成功,然后我只想应用其他逻辑。这是我要上传的代码。
@Bean
public DefaultSftpSessionFactory sftpSessionFactory() throws IOException {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost(config.getSftpHost());
factory.setPort(Integer.parseInt(config.getSftpPort()));
factory.setUser(config.getSftpUser());
factory.setAllowUnknownKeys(true);
factory.setTimeout(10000);
factory.setPrivateKey(new ClassPathResource(config.getPrivateKey()));
}
@Bean
@ServiceActivator(inputChannel = "toSftpChannel")
public SftpMessageHandler uploadHandler() throws IOException {
SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
handler.setRemoteDirectoryExpression(new LiteralExpression(config.getSftpRemoteDirectory()));
handler.setFileNameGenerator(new FileNameGenerator() {
@Override
public String generateFileName(Message<?> message) {
if (message.getPayload() instanceof File) {
return ((File) message.getPayload()).getName();
} else {
throw new IllegalArgumentException("File expected as payload.");
}
}
});
return handler;
}
@MessagingGateway
public interface UploadGateway {
@Gateway(requestChannel = "toSftpChannel")
void upload(File file);
}
我看到日志看起来不错。验证文件正在上传到 SFTP 服务器。但不知何故,我无法确保文件正在上传到服务器上。请告知如何添加代码以确保文件成功上传。
jsch Connecting to info.xyz.com port 22
jsch Connection established
jsch Remote version string: SSH-.0-Internal_SFTP__100
jsch Local version string: SSH-.0-JSCH-0.1.4
jsch CheckCiphers: aes6-ctr,aes19-ctr,aes18-ctr,aes6-cbc,aes19-cbc,aes18-cbc,des-ctr,arcfour,arcfour18,arcfour6
jsch CheckKexes: diffie-hellman-group14-sha1,ecdh-sha-nistp6,ecdh-sha-nistp84,ecdh-sha-nistp1
jsch CheckSignatures: ecdsa-sha-nistp6,ecdsa-sha-nistp84,ecdsa-sha-nistp1
jsch SSH_MSG_KEXINIT sent
jsch SSH_MSG_KEXINIT received
jsch kex: server: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha6,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
jsch kex: server: ssh-rsa
jsch kex: server: aes18-ctr,aes6-cbc,aes19-cbc,aes18-cbc,aes6-ctr,aes19-ctr,des-cbc,blowfish-cbc,arcfour,arcfour18,arcfour6
jsch kex: server: aes18-ctr,aes6-cbc,aes19-cbc,aes18-cbc,aes6-ctr,aes19-ctr,des-cbc,blowfish-cbc,arcfour,arcfour18,arcfour6
jsch kex: server: hmac-sha-6,hmac-sha1-96,hmac-sha1,hmac-sha-1,hmac-md,hmac-sha-1-96,hmac-sha-6-96,hmac-md-96,hmac-sha6,hmac-sha6@ssh.com
jsch kex: server: hmac-sha6,hmac-sha-6,hmac-sha1-96,hmac-sha1,hmac-sha-1,hmac-md,hmac-sha-1-96,hmac-sha-6-96,hmac-md-96,hmac-sha6@ssh.com
jsch kex: server: none
jsch kex: server: none
jsch kex: server:
jsch kex: server:
jsch kex: client: ecdh-sha-nistp6,ecdh-sha-nistp84,ecdh-sha-nistp1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha6,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
jsch kex: client: ssh-rsa,ssh-dss,ecdsa-sha-nistp6,ecdsa-sha-nistp84,ecdsa-sha-nistp1
jsch kex: client: aes18-ctr,aes18-cbc,des-ctr,des-cbc,blowfish-cbc,aes19-
ctr,aes19-cbc,aes6-ctr,aes6-cbc
jsch kex: client: aes18-ctr,aes18-cbc,des-ctr,des-cbc,blowfish-cbc,aes19-
ctr,aes19-cbc,aes6-ctr,aes6-cbc
jsch kex: client: hmac-md,hmac-sha1,hmac-sha-6,hmac-sha1-96,hmac-md-96
jsch kex: client: hmac-md,hmac-sha1,hmac-sha-6,hmac-sha1-96,hmac-md-96
jsch kex: client: none
jsch kex: client: none
jsch kex: client:
jsch kex: client:
jsch kex: server->client aes1-ctr hmac-md none
jsch kex: client->server aes1-ctr hmac-md none
jsch SSH_MSG_KEXDH_INIT sent
jsch expecting SSH_MSG_KEXDH_REPLY
jsch ssh_rsa_verify: signature true
jsch Host 'info.xyz.com' is known and matches the RSA host key
jsch SSH_MSG_NEWKEYS sent
jsch SSH_MSG_NEWKEYS received
jsch SSH_MSG_SERVICE_REQUEST sent
jsch SSH_MSG_SERVICE_ACCEPT received
jsch Authentications that can continue: publickeykeyboard-interactivepassword
jsch Next authentication method: publickey
jsch Authentication succeeded (publickey).
jsch Disconnecting from info.xyz.com port 22
解决方案
不清楚你的意思;如果上传失败,会抛出异常。
您可以将重试建议添加SftpMessageHandler
到重试。
推荐阅读
- sql - 如何在 SQL 中找到一对数字
- python - 找到两个列表之间的共同元素?
- python - 使用 anyOf 关键字验证 jsonschema 时设置默认值
- ios - 是否有一次设置 UI 图形上下文绘图属性,而不是每次都绘制?
- python - 将 PDF 转换为图像打印输出没有打印功能
- tensorflow - 如何在 TensorFlow Servings batching_parameters.txt 文件中将 max_batch_size 设置为无穷大
- python - 不允许并发运行 Azure devops
- node.js - Angular 用户数据以 [object object] 形式出现
- c# - 如何在不删除html标签的情况下将html转换为文本
- javascript - 检查文本是否溢出到 svg 的文本元素之外