apache/seatunnel · error · IOException
create(): Mkdirs failed to create: %s
Error message
create(): Mkdirs failed to create: %s
What it means
SFTPFileSystem.create() throws this IOException when it cannot create the parent directories for the file being opened for write. Before putting the file, it calls mkdirs() on the parent path; if that returns false or the parent is null (no parent could be resolved), it fails with a formatted message naming the parent directory. It is a wrapper so the user sees which directory could not be created.
Source
Thrown at seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java:534
short replication,
long blockSize,
Progressable progress)
throws IOException {
final ChannelSftp client = connect();
try {
Path workDir = new Path(client.pwd());
Path absolute = makeAbsolute(workDir, f);
if (exists(client, f)) {
if (overwrite) {
delete(client, f, false);
} else {
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;
throw new IOException(String.format(E_CREATE_DIR, parent));
}
final String previousCwd = client.pwd();
client.cd(parent.toUri().getPath());
OutputStream os = client.put(f.getName());
client.cd(previousCwd);
return new FSDataOutputStream(os, statistics) {
@Override
public void close() throws IOException {
try {
super.close();
} finally {
disconnect(client);
}
}
};
} catch (Exception e) {
disconnectAfterFailure(client, e);
if (e instanceof IOException) {View on GitHub (pinned to cf67b549a7)
Solutions
- Check that the SFTP user has write permission on the parent directory printed in the message (chmod/chown on the server).
- Pre-create the parent directory on the SFTP server manually (mkdir -p via ssh).
- Verify the output path is correct and absolute relative to the SFTP user's chroot/home; fix the configured path.
- Check the SFTP server logs for the underlying mkdir failure reason.
Example fix
// before
stream = sftpFileSystem.create(new Path("sftp://host/data/out/result.txt"));
// after
Path out = new Path("sftp://host/data/out/result.txt");
sftpFileSystem.mkdirs(out.getParent()); // ensure parent exists with proper perms
stream = sftpFileSystem.create(out); Defensive patterns
Strategy: validation
Validate before calling
Path parent = outPath.getParent();
if (parent == null || !sftpFs.exists(parent)) {
sftpFs.mkdirs(parent); // or fail early with a clear message
}
if (!sftpFs.exists(parent)) throw new IOException("Cannot create parent dir: " + parent); Try / catch
try (FSDataOutputStream out = sftpFs.create(outPath)) { ... }
catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Mkdirs failed")) {
// handle missing/forbidden parent dir
} else throw e;
} Prevention
- Pre-create output directories with correct permissions before the job runs
- Verify SFTP user write permissions on target directories
- Use paths relative to the SFTP user's home/chroot consistently
When it happens
Trigger: Calling FileSystem.create() (or opening a sink that writes via this filesystem) where the parent directory chain on the SFTP server does not exist and cannot be created — typically due to missing write permission on the remote parent, or the parent path being invalid/rootless.
Common situations: Writing to a remote output path like sftp://host/data/output/result.txt when /data/output does not exist and the SFTP user lacks permission to create it; SFTP user chrooted to a directory so absolute paths like /home/user/... do not resolve; typo in configured output directory.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- SftpException wrapped (pwd failed while creating directory)
- Can't make directory for path "%s" under "%s".
- Can't make directory for path %s since it is a file.
- SftpException wrapped (pwd failed while deleting)
- SftpException wrapped (pwd failed while listing status)
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/938996e587c4a11d.
Report an issue: GitHub.