spring integration sftp mainframe :failed to write file; nested exception is 3: Permission denied

后端 未结 2 2091
青春惊慌失措
青春惊慌失措 2021-01-21 14:15

I am trying to sft file to mainframe using spring integration sftp:outbound-gateway: this is configuration:



        
相关标签:
2条回答
  • 2021-01-21 15:05

    Why am I getting “Permission denied at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)”

    We received this error because on some sftp servers “/” meant the root of the user’s home directory, but on others it literally meant the server root to which the user obviously did not have permissions to write. We also received this on some sftp servers when the directory to which the user was trying to write didn’t exist.

    Another quete:

    I was having the problem also with SFTP and figured out that in the parameters for the File Writer FTP in the box to the right of the ftp server name or address you have to put the fully qualified path of the folder you are going to put files in. Otherwise the MIRTH SFTP tries to change directory to / and gets a permission denied. eg. sftp:// 111.222.333.444 / foldera/folderb/folderc/

    To find out what foldera/folderb/folderc/ should be use some sort of SFTP client that works (not MIRTH) and when it connects you it should show the path of folders that you are in.

    This worked for me.

    So, your issue that your SFTP path starts with /. The code from 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;
    }
    

    Try to figure out how to avoid / in the beginning.

    0 讨论(0)
  • 2021-01-21 15:07

    To follow up on what Artem pointed out, when sFTPing to, for example, a cloud Axway sFTP server, where I was told that the current working directory was "/"

    First, I used a terminal sftp client:

    $ sftp username@mft-xxx.axwaycloud.com
    sftp> pwd
    Remote working directory: /
    

    This isn't the root /, but the chrooted directory so that I have no way to determine what the absolute path is. The below code String ftpRemoteDestinationPath = "/" + tempFile.getName(); works though in this situation:

        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();
            }
        }
    
    0 讨论(0)
提交回复
热议问题