{"record":{"id":"7aa93562e5641715","repo":"apache/hadoop","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":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java","lineNumber":338,"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    OutputStream outputStream = client.storeFileStream(file.getName());\n\n    if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {\n      // The ftpClient is an inconsistent state. Must close the stream\n      // which in turn will logout and disconnect from FTP server\n      if (outputStream != null) {\n        IOUtils.closeStream(outputStream);\n      }\n      disconnect(client);\n      throw new IOException(\"Unable to create file: \" + file + \", Aborting\");","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java#L320-L356","documentation":"Before storing a file, create() ensures the parent directory chain exists by calling mkdirs; if that returns false (some MKD was refused), create aborts with this IOException after disconnecting. When the target's parent is null it is normalized to '/'.","triggerScenarios":"FTP user lacks write permission on the deepest existing ancestor directory; an intermediate path component already exists as a file so MKD fails mid-chain; server quota exhausted or read-only share.","commonSituations":"Writing into /upload/<user>/ trees where only /upload is writable; path components created by others with restrictive modes; disk full on the FTP server.","solutions":["Create the parent explicitly first: if (!fs.mkdirs(parent)) { ... } and inspect the FTP server reply for the failing MKD","Verify write permission on the intended parent via getFileStatus(parent).getPermission() containing FsAction.WRITE","Make sure no intermediate component is a file — mkdirs cannot traverse a file","Check server disk space / quota"],"exampleFix":"// before\nFSDataOutputStream out = fs.create(new Path(\"/upload/alice/out/part-0\"), true);\n// IOException: create(): Mkdirs failed to create: /upload/alice/out\n\n// after\nPath parent = new Path(\"/upload/alice/out\");\nif (!fs.mkdirs(parent)) {\n  throw new IOException(\"Cannot create parent \" + parent + \" - check write permission\");\n}\nFSDataOutputStream out = fs.create(new Path(parent, \"part-0\"), true);","handlingStrategy":"validation","validationCode":"Path parent = file.getParent() != null ? file.getParent() : new Path(\"/\");\nif (!fs.exists(parent) && !fs.mkdirs(parent)) {\n  throw new IOException(\"Cannot create parent directory \" + parent\n      + \" - check FTP write permission / disk space\");\n}\nFSDataOutputStream out = fs.create(file, true);","typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(file, true);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Mkdirs failed\")) {\n    throw new IOException(\"FTP server refused to create parent dirs for \" + file\n        + \" - verify write permission on ancestor dirs\", e);\n  }\n  throw e;\n}","preventionTips":["Pre-create directory trees during deployment where permissions are known-good","Ensure no intermediate path component is a file before writing nested outputs","Grant the FTP account write access on the upload root once, not per-job"],"tags":["ftp","mkdirs","create","permission-denied"],"backgroundTag":"directory-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}