files-community/Files · error · IOException

Directory was not successfully created.

Error message

Directory was not successfully created.

What it means

Thrown by FtpStorageFolder.CreateFolderAsync when AsyncFtpClient.CreateDirectory returns false, meaning FluentFTP could not create the remote directory. Unlike the existence check, this is a genuine creation failure: insufficient permissions, a missing parent directory, invalid characters in the name, or the server rejecting MKD.

Source

Thrown at src/Files.App.Storage/Ftp/FtpStorageFolder.cs:168

			{
				// File creation failed
				throw new IOException("File creation failed.");
			}
		}

		/// <inheritdoc/>
		public async Task<IChildFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
		{
			using var ftpClient = GetFtpClient();
			await ftpClient.EnsureConnectedAsync(cancellationToken);

			var newPath = $"{Id}/{desiredName}";
			if (overwrite && await ftpClient.DirectoryExists(newPath, cancellationToken))
				throw new IOException("Directory already exists.");

			var isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite, cancellationToken);
			if (!isSuccessful)
				throw new IOException("Directory was not successfully created.");

			return new FtpStorageFolder(newPath, desiredName, this);
		}
	}
}

View on GitHub (pinned to 68c68a58d4)

Solutions

  1. Create parent directories first; FluentFTP's CreateDirectory has an overload/force flag to create intermediates - use it.
  2. Sanitize the desired name for the target server's allowed character set before calling CreateFolderAsync.
  3. Check the FluentFTP reply (LastReply) for the MKD failure code and report it.
  4. Verify the FTP account has directory-creation rights on the target path.

Example fix

// before
var isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite, cancellationToken);

// after - create the full path including parents
var isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite || forceCreateParents: true, cancellationToken);
if (!isSuccessful)
    throw new IOException($"Directory was not successfully created: {ftpClient.LastReply?.Code} {ftpClient.LastReply?.Message}");
Defensive patterns

Strategy: retry

Validate before calling

// Ensure parent exists and name is valid before creating.
if (!await ftpClient.DirectoryExists(parentPath, ct))
    await ftpClient.CreateDirectory(parentPath, true, ct);
if (desiredName.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
    throw new ArgumentException("Invalid directory name.");

Try / catch

try { return await folder.CreateFolderAsync(name, overwrite, ct); }
catch (IOException ex) when (ex.Message.Contains("not successfully created"))
{ var reply = ftpClient.LastReply; /* inspect and report */ throw; }

Prevention

When it happens

Trigger: CreateDirectory(newPath, overwrite, ct) returning false. Happens when the parent path does not exist (FTP MKD is typically non-recursive), the user lacks create permission, the name contains illegal characters, or the server does not allow the operation.

Common situations: Trying to create nested folders in one call without creating parents first; accounts restricted to a home directory; names with characters the server filesystem rejects (backslashes, leading dots, reserved names).

Related errors


AI-assisted analysis of files-community/Files@68c68a58d4 (2026-08-13). Data as JSON: /api/errors/fe351b1bec0431a4. Report an issue: GitHub.