我正在尝试使用 Spring 集成 sftp:outbound-gateway 将 sftp 文件发送到大型机:
这是配置:
<sftp:outbound-gateway id="putGateway"
session-factory="sftpSessionFactory"
request-channel="sftpFileInputChannel"
command="put"
expression="payload"
remote-directory="${remote.upload.directory}"
remote-filename-generator-expression="'${remote.upload.filename}'"
use-temporary-file-name="false"
reply-channel="replayFromPutSftpChannel"/>
where
remote.upload.filename.credit.fmpl=/!DTS4.UP.G3TRF.S60304
remote.upload.directory=/
我收到如下异常:
Caused by: org.springframework.integration.MessagingException: Failed to write to '//!DTS4.UP.G3TRF.S60304' while uploading the file
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:392)
at org.springframework.integration.file.remote.RemoteFileTemplate.access$500(RemoteFileTemplate.java:56)
at org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:213)
... 46 more
Caused by: org.springframework.core.NestedIOException: failed to write file; nested exception is 3: Permission denied
at org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:158)
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:385)
... 48 more
Caused by: 3: Permission denied
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2629)
at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:545)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:491)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:454)
at org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:155)
如果我使用 sftp 客户端从命令行上传,则以下工作有效:
put filename //!DTS4.UP.G3TRF.S60304
但通过 spring 集成,它不会。
我尝试 sftp 到的服务器是:IBM z/OS 大型机。
如果您知道如何解决该问题,请提供帮助。
谢谢你,
安娜
为了跟进 Artem 指出的内容,例如,当 sFTP 到云 Axway sFTP 服务器时,我被告知当前工作目录是“/”
首先,我使用了终端 sftp 客户端:
$ sftp [email protected]
sftp> pwd
Remote working directory: /
这不是根 /,而是 chroot 目录,因此我无法确定绝对路径是什么。下面的代码 String ftpRemoteDestinationPath = "/" + tempFile.getName();但在这种情况下有效:
if (tempFile.exists()) {
try {
axwaySftpRemoteFileTemplate.execute((SessionCallback<ChannelSftp.LsEntry, Void>) session -> {
String ftpRemoteDestinationPath = "/" + tempFile.getName();
logger.info("FTP local file residing on server: [" + tempFile.getAbsolutePath() + "]");
InputStream targetStream = new FileInputStream(tempFile);
logger.debug("sftp uploading file: [" + tempFile.getName() + "] using channel connected to an sftp server :[" + session.getClientInstance().toString() + "]");
session.write(targetStream, ftpRemoteDestinationPath);
return null;
});
} catch (Exception e) {
logger.error("Could not send file per SFTP: " + e);
throw new SomeRuntimeSftpException("Error FTPing file " + tempFile.getAbsolutePath() + " " + e.getMessage());
}
finally {
tempFile.delete();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)