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

后端 未结 2 2090
青春惊慌失措
青春惊慌失措 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: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) 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();
            }
        }
    

提交回复
热议问题