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
- 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).
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
- 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.
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
- File already exists: %s
- {} already exists
- Can not create '%s' file, because parent folder does not exi
- {} is a directory
- Parent directory doesn't exist: {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/4fe03ad46fd51ac0.
Report an issue: GitHub.