spring集成sftp主机:无法写入文件;嵌套异常为3:权限被拒绝

问题描述 投票:2回答:2

我正在尝试使用Spring Integration sftp:outbound-gateway将文件保存到大型机:这是配置:

<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大型机。

如果您知道如何解决此问题,请提供帮助。

谢谢,安娜

java sftp spring-integration jsch mainframe
2个回答
0
投票

为什么我会收到“ com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)的权限被拒绝”]

我们收到此错误的原因是,在某些sftp服务器上,“ /”表示用户主目录的根,而在其他sftp服务器上,它的字面意思是用户显然没有写权限的服务器根。当用户尝试写入的目录不存在时,我们还在某些sftp服务器上收到了此消息。

另一个队列:

我在使用SFTP时也遇到了问题,并且在ftp服务器名称或地址右边的框中找到了File Writer FTP的参数,您必须输入要转到的文件夹的标准路径。放入文件。否则,MIRTH SFTP尝试将目录更改为/并获得拒绝权限。例如。 sftp:// 111.222.333.444 / foldera / folderb / folderc /

要找出应该使用哪种可以工作的SFTP客户端(不是MIRTH)来使用哪个foldera / folderb / folderc /,当它与您连接时,它应该显示您所在文件夹的路径。

这对我有用。

因此,您的SFTP路径以/开头的问题。来自ChannelSftp.put的代码:

dst=remoteAbsolutePath(dst);
...
private String remoteAbsolutePath(String path) throws SftpException{
   if(path.charAt(0)=='/') return path;
   String cwd=getCwd();
   if(cwd.endsWith("/")) return cwd+path;
   return cwd+"/"+path;
}

尝试弄清楚如何一开始就避免/


0
投票

[跟进Artem所指出的,例如,当通过sFTP传输到云Axway sFTP服务器时,被告知当前工作目录为“ /”

首先,我使用了终端sftp客户端:

$ sftp [email protected]
sftp> pwd
Remote working directory: /

这不是根目录/,而是chroot目录,因此我无法确定绝对路径。下面的代码字符串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();
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.