{"record":{"id":"4fe03ad46fd51ac0","repo":"apache/hadoop","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":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java","lineNumber":569,"sourceCode":"    try {\n      workDir = new Path(client.pwd());\n    } catch (SftpException e) {\n      throw new IOException(e);\n    }\n    Path absolute = makeAbsolute(workDir, f);\n    if (exists(client, f)) {\n      if (overwrite) {\n        delete(client, f, false);\n      } else {\n        disconnect(client);\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      disconnect(client);\n      throw new IOException(String.format(E_CREATE_DIR, parent));\n    }\n    OutputStream os;\n    try {\n      final String previousCwd = client.pwd();\n      client.cd(parent.toUri().getPath());\n      os = client.put(f.getName());\n      client.cd(previousCwd);\n    } catch (SftpException e) {\n      throw new IOException(e);\n    }\n    FSDataOutputStream fos = new FSDataOutputStream(os, statistics) {\n      @Override\n      public void close() throws IOException {\n        super.close();\n        disconnect(client);\n      }\n    };\n","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java#L551-L587","documentation":"Thrown by SFTPFileSystem.create when the parent directory of the file being created is null or mkdirs(client, parent, FsPermission.getDefault()) returns false. The message reports the parent path, not the file, and means the SFTP server refused or failed to create the directory hierarchy.","triggerScenarios":"fs.create(f) where f's parent directory does not exist and the SFTP server denies mkdir (no write permission on the target dir), or a component of the parent path is an existing regular file so the mkdir cannot succeed.","commonSituations":"The SFTP account lacks write access to the upload directory; chrooted/sandboxed SFTP accounts that can only write under a specific subtree; a previous run created a regular file at a path now needed as a directory; read-only export on the server side.","solutions":["Verify the SFTP login has write (and traverse) permission on the parent directory: connect with sftp and try 'mkdir' + 'put' by hand.","Pre-create the hierarchy explicitly and check the boolean: if (!fs.mkdirs(parent)) { fail with a clear message } — this isolates the permission problem from file creation.","Ensure no regular file occupies any path component of the intended parent (delete or rename it)."],"exampleFix":"// before\nFSDataOutputStream out = fs.create(new Path(\"sftp://host/incoming/new/dir/file.dat\"));\n\n// after\nPath parent = new Path(\"sftp://host/incoming/new/dir\");\nif (!fs.exists(parent) && !fs.mkdirs(parent)) {\n  throw new IOException(\"cannot create (permission?): \" + parent);\n}\nFSDataOutputStream out = fs.create(new Path(parent, \"file.dat\"));","handlingStrategy":"validation","validationCode":"Path parent = f.getParent();\nif (!fs.exists(parent) && !fs.mkdirs(parent)) {\n  throw new IOException(\"cannot create parent (permissions?): \" + parent);\n}\nFSDataOutputStream out = fs.create(f, true);","typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(f, true);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Mkdirs failed\")) {\n    // parent not creatable: check SFTP account write permissions\n  } else {\n    throw e;\n  }\n}","preventionTips":["Smoke-test the SFTP account at deploy time: mkdir + put + rm on the target directory.","Pre-create output directory trees with explicit mkdirs and boolean checks.","Ensure no regular file shadows any directory component of the target path."],"tags":["sftp","create","mkdirs-failed","permission-denied","hadoop"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}