apache/hadoop · error · IOException

create(): Mkdirs failed to create: %s

Error message

create(): Mkdirs failed to create: %s

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java:569

    try {
      workDir = new Path(client.pwd());
    } catch (SftpException e) {
      throw new IOException(e);
    }
    Path absolute = makeAbsolute(workDir, f);
    if (exists(client, f)) {
      if (overwrite) {
        delete(client, f, false);
      } else {
        disconnect(client);
        throw new IOException(String.format(E_FILE_EXIST, f));
      }
    }
    Path parent = absolute.getParent();
    if (parent == null || !mkdirs(client, parent, FsPermission.getDefault())) {
      parent = (parent == null) ? new Path("/") : parent;
      disconnect(client);
      throw new IOException(String.format(E_CREATE_DIR, parent));
    }
    OutputStream os;
    try {
      final String previousCwd = client.pwd();
      client.cd(parent.toUri().getPath());
      os = client.put(f.getName());
      client.cd(previousCwd);
    } catch (SftpException e) {
      throw new IOException(e);
    }
    FSDataOutputStream fos = new FSDataOutputStream(os, statistics) {
      @Override
      public void close() throws IOException {
        super.close();
        disconnect(client);
      }
    };

View on GitHub (pinned to 2add963021)

Solutions

  1. Verify the SFTP login has write (and traverse) permission on the parent directory: connect with sftp and try 'mkdir' + 'put' by hand.
  2. 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.
  3. Ensure no regular file occupies any path component of the intended parent (delete or rename it).

Example fix

// before
FSDataOutputStream out = fs.create(new Path("sftp://host/incoming/new/dir/file.dat"));

// after
Path parent = new Path("sftp://host/incoming/new/dir");
if (!fs.exists(parent) && !fs.mkdirs(parent)) {
  throw new IOException("cannot create (permission?): " + parent);
}
FSDataOutputStream out = fs.create(new Path(parent, "file.dat"));
Defensive patterns

Strategy: validation

Validate before calling

Path parent = f.getParent();
if (!fs.exists(parent) && !fs.mkdirs(parent)) {
  throw new IOException("cannot create parent (permissions?): " + parent);
}
FSDataOutputStream out = fs.create(f, true);

Try / catch

try {
  out = fs.create(f, true);
} catch (IOException e) {
  if (e.getMessage() != null && e.getMessage().contains("Mkdirs failed")) {
    // parent not creatable: check SFTP account write permissions
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/4fe03ad46fd51ac0. Report an issue: GitHub.