{"record":{"id":"100fcbd9e3cd2385","repo":"apache/seatunnel","slug":"sftpexception-wrapped-pwd-failed-while-creating-d","errorCode":null,"errorMessage":"SftpException wrapped (pwd failed while creating directory)","messagePattern":"SftpException wrapped \\(pwd failed while creating directory\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java","lineNumber":307,"sourceCode":"    }\n\n    private FsPermission getPermissions(LsEntry sftpFile) {\n        return new FsPermission((short) sftpFile.getAttrs().getPermissions());\n    }\n\n    /**\n     * Convenience method, so that we don't open a new connection when using this method from within\n     * another method. Otherwise every API invocation incurs the overhead of opening/closing a TCP\n     * connection.\n     */\n    private boolean mkdirs(ChannelSftp client, Path file, FsPermission permission)\n            throws IOException {\n        boolean created = true;\n        Path workDir;\n        try {\n            workDir = new Path(client.pwd());\n        } catch (SftpException e) {\n            throw new IOException(e);\n        }\n        Path absolute = makeAbsolute(workDir, file);\n        String pathName = absolute.getName();\n        if (!exists(client, absolute)) {\n            Path parent = absolute.getParent();\n            created = parent == null || mkdirs(client, parent, FsPermission.getDefault());\n            if (created) {\n                String parentDir = parent.toUri().getPath();\n                boolean succeeded = true;\n                try {\n                    final String previousCwd = client.pwd();\n                    client.cd(parentDir);\n                    LOG.debug(\"Creating directory \" + pathName);\n                    client.mkdir(pathName);\n                    client.cd(previousCwd);\n                } catch (SftpException e) {\n                    throw new IOException(String.format(E_MAKE_DIR_FORPATH, pathName, parentDir));\n                }","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java#L289-L325","documentation":"In mkdirs(), the first step resolves the server working directory with client.pwd(); an SftpException here is wrapped in a plain IOException. Directory creation cannot proceed because the code cannot compute the absolute path of the directory to create.","triggerScenarios":"mkdirs() (reached directly, from create()'s parent-creation, or recursively) runs on a dead/disconnected channel or a server that rejects the realpath request behind pwd().","commonSituations":"Connection dropped before a write step; session timed out between read and write phases; chrooted accounts whose server rejects realpath; channel reused after a prior operation threw and left it closed.","solutions":["Reconnect the SFTP channel and retry mkdirs","Verify with an sftp client that pwd works for the account (chroot/restricted shell)","Check server logs for realpath failures at the time of the job","Ensure the channel/session is kept alive (SSH keepalive settings) during long jobs","Pass absolute paths so pwd resolution is less critical, though pwd is still called internally"],"exampleFix":"// before\nfs.mkdirs(new Path(\"/out/2026/09/10\")); // throws if channel dead\n// after\nif (channel == null || !channel.isConnected()) {\n    channel = openConnectedChannel(conf);\n}\nfs.mkdirs(new Path(\"/out/2026/09/10\"));","handlingStrategy":"retry","validationCode":"if (channel == null || !channel.isConnected()) { channel = openConnectedChannel(conf); }","typeGuard":null,"tryCatchPattern":"try { fs.mkdirs(path); } catch (IOException e) { reconnect(); fs.mkdirs(path); // single retry after refresh }","preventionTips":["Enable SSH keepalive","Reconnect on any IOException before retry","Probe pwd() at job start","Test chrooted accounts interactively","Reuse one healthy channel per job phase"],"tags":["sftp","mkdir","pwd","connection"],"backgroundTag":"mkdir-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}