{"record":{"id":"317e4b55122478a1","repo":"apache/seatunnel","slug":"create-mkdirs-failed-to-create-parent","errorCode":null,"errorMessage":"create(): Mkdirs failed to create: ${parent}","messagePattern":"create\\(\\): Mkdirs failed to create: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java","lineNumber":369,"sourceCode":"        try {\n            status = getFileStatus(client, file);\n        } catch (FileNotFoundException fnfe) {\n            status = null;\n        }\n        if (status != null) {\n            if (overwrite && !status.isDirectory()) {\n                delete(client, file, false);\n            } else {\n                disconnect(client);\n                throw new FileAlreadyExistsException(\"File already exists: \" + file);\n            }\n        }\n\n        Path parent = absolute.getParent();\n        if (parent == null || !mkdirs(client, parent, FsPermission.getDirDefault())) {\n            parent = (parent == null) ? new Path(\"/\") : parent;\n            disconnect(client);\n            throw new IOException(\"create(): Mkdirs failed to create: \" + parent);\n        }\n        client.allocate(bufferSize);\n        // Change to parent directory on the server. Only then can we write to the\n        // file on the server by opening up an OutputStream. As a side effect the\n        // working directory on the server is changed to the parent directory of the\n        // file. The FTP client connection is closed when close() is called on the\n        // FSDataOutputStream.\n        client.changeWorkingDirectory(parent.toUri().getPath());\n        FSDataOutputStream fos =\n                new FSDataOutputStream(client.storeFileStream(file.getName()), statistics) {\n                    @Override\n                    public void close() throws IOException {\n                        super.close();\n                        if (!client.isConnected()) {\n                            throw new FTPException(\"Client not connected\");\n                        }\n                        boolean cmdCompleted = client.completePendingCommand();\n                        disconnect(client);","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java#L351-L387","documentation":"SeaTunnelFTPFileSystem.create() ensures the parent directory of the target path exists by calling mkdirs(client, parent, ...). If parent is null or mkdirs fails, it disconnects and throws IOException('create(): Mkdirs failed to create: <parent>').","triggerScenarios":"Calling create(file) where the parent directory cannot be created on the FTP server — server-side permission denial on the parent path, path component conflict (a file exists with the directory's name), or an unresolvable/null parent.","commonSituations":"FTP account lacks write permission on the output directory; output path typos creating deep nonexistent trees; a file occupies one of the path components so mkdir fails; FTP server enforces a chroot/home prefix the absolute path ignores.","solutions":["Pre-create the parent directories manually on the FTP server or grant the FTP user write/create permission there","Verify no regular file exists with the same name as one of the parent path components","Check the FTP server logs for the MKD command reply to see the exact server-side failure","Confirm the path layout matches the server's root/home directory semantics"],"exampleFix":"// before\nfs.create(new Path(\"ftp://host/out/2024/09/result.csv\")) // /out/2024 not writable by ftp user\n// after\n# grant write perms or pre-create: mkdir -p /out/2024/09 on the server with correct ownership","handlingStrategy":"try-catch","validationCode":"// Preflight: ensure parent dir exists or can be created via a plain FTP client\nFTPClient c = connect();\nPath parent = path.getParent();\nboolean ok = parent == null || c.changeWorkingDirectory(parent.toUri().getPath());\ndisconnect(c);\nif (!ok) throw new IllegalStateException(\"Parent not writable/unreachable on FTP server: \" + parent);","typeGuard":null,"tryCatchPattern":"try {\n    return fs.create(path);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"create(): Mkdirs failed\")) {\n        throw new IllegalStateException(\"Cannot create parent dir \" + path.getParent()\n            + \" — check FTP user write permissions and path components\", e);\n    }\n    throw e;\n}","preventionTips":["Pre-create output directories with correct ownership for the FTP account","Ensure no file shares a name with a directory component of the output path","Confirm the path respects the server's chroot/home root","Test MKD via an interactive FTP client to see the server's exact error"],"tags":["ftp","filesystem","mkdir","permissions"],"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"}