{"record":{"id":"938996e587c4a11d","repo":"apache/seatunnel","slug":"create-mkdirs-failed-to-create-s","errorCode":null,"errorMessage":"create(): Mkdirs failed to create: %s","messagePattern":"create\\(\\): Mkdirs failed to create: (.+?)","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":534,"sourceCode":"            short replication,\n            long blockSize,\n            Progressable progress)\n            throws IOException {\n        final ChannelSftp client = connect();\n        try {\n            Path workDir = new Path(client.pwd());\n            Path absolute = makeAbsolute(workDir, f);\n            if (exists(client, f)) {\n                if (overwrite) {\n                    delete(client, f, false);\n                } else {\n                    throw new IOException(String.format(E_FILE_EXIST, f));\n                }\n            }\n            Path parent = absolute.getParent();\n            if (parent == null || !mkdirs(client, parent, FsPermission.getDefault())) {\n                parent = (parent == null) ? new Path(\"/\") : parent;\n                throw new IOException(String.format(E_CREATE_DIR, parent));\n            }\n            final String previousCwd = client.pwd();\n            client.cd(parent.toUri().getPath());\n            OutputStream os = client.put(f.getName());\n            client.cd(previousCwd);\n            return new FSDataOutputStream(os, statistics) {\n                @Override\n                public void close() throws IOException {\n                    try {\n                        super.close();\n                    } finally {\n                        disconnect(client);\n                    }\n                }\n            };\n        } catch (Exception e) {\n            disconnectAfterFailure(client, e);\n            if (e instanceof IOException) {","sourceCodeStart":516,"sourceCodeEnd":552,"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#L516-L552","documentation":"SFTPFileSystem.create() throws this IOException when it cannot create the parent directories for the file being opened for write. Before putting the file, it calls mkdirs() on the parent path; if that returns false or the parent is null (no parent could be resolved), it fails with a formatted message naming the parent directory. It is a wrapper so the user sees which directory could not be created.","triggerScenarios":"Calling FileSystem.create() (or opening a sink that writes via this filesystem) where the parent directory chain on the SFTP server does not exist and cannot be created — typically due to missing write permission on the remote parent, or the parent path being invalid/rootless.","commonSituations":"Writing to a remote output path like sftp://host/data/output/result.txt when /data/output does not exist and the SFTP user lacks permission to create it; SFTP user chrooted to a directory so absolute paths like /home/user/... do not resolve; typo in configured output directory.","solutions":["Check that the SFTP user has write permission on the parent directory printed in the message (chmod/chown on the server).","Pre-create the parent directory on the SFTP server manually (mkdir -p via ssh).","Verify the output path is correct and absolute relative to the SFTP user's chroot/home; fix the configured path.","Check the SFTP server logs for the underlying mkdir failure reason."],"exampleFix":"// before\nstream = sftpFileSystem.create(new Path(\"sftp://host/data/out/result.txt\"));\n// after\nPath out = new Path(\"sftp://host/data/out/result.txt\");\nsftpFileSystem.mkdirs(out.getParent()); // ensure parent exists with proper perms\nstream = sftpFileSystem.create(out);","handlingStrategy":"validation","validationCode":"Path parent = outPath.getParent();\nif (parent == null || !sftpFs.exists(parent)) {\n    sftpFs.mkdirs(parent); // or fail early with a clear message\n}\nif (!sftpFs.exists(parent)) throw new IOException(\"Cannot create parent dir: \" + parent);","typeGuard":null,"tryCatchPattern":"try (FSDataOutputStream out = sftpFs.create(outPath)) { ... }\ncatch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Mkdirs failed\")) {\n        // handle missing/forbidden parent dir\n    } else throw e;\n}","preventionTips":["Pre-create output directories with correct permissions before the job runs","Verify SFTP user write permissions on target directories","Use paths relative to the SFTP user's home/chroot consistently"],"tags":["sftp","io","mkdir","file-write"],"backgroundTag":"mkdir-permission-denied","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"}