{"record":{"id":"fe351b1bec0431a4","repo":"files-community/Files","slug":"directory-was-not-successfully-created","errorCode":null,"errorMessage":"Directory was not successfully created.","messagePattern":"Directory was not successfully created\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Files.App.Storage/Ftp/FtpStorageFolder.cs","lineNumber":168,"sourceCode":"\t\t\t{\n\t\t\t\t// File creation failed\n\t\t\t\tthrow new IOException(\"File creation failed.\");\n\t\t\t}\n\t\t}\n\n\t\t/// <inheritdoc/>\n\t\tpublic async Task<IChildFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tusing var ftpClient = GetFtpClient();\n\t\t\tawait ftpClient.EnsureConnectedAsync(cancellationToken);\n\n\t\t\tvar newPath = $\"{Id}/{desiredName}\";\n\t\t\tif (overwrite && await ftpClient.DirectoryExists(newPath, cancellationToken))\n\t\t\t\tthrow new IOException(\"Directory already exists.\");\n\n\t\t\tvar isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite, cancellationToken);\n\t\t\tif (!isSuccessful)\n\t\t\t\tthrow new IOException(\"Directory was not successfully created.\");\n\n\t\t\treturn new FtpStorageFolder(newPath, desiredName, this);\n\t\t}\n\t}\n}\n","sourceCodeStart":150,"sourceCodeEnd":174,"githubUrl":"https://github.com/files-community/Files/blob/68c68a58d4d6a5f7197e07c8fff85cfd4279c78b/src/Files.App.Storage/Ftp/FtpStorageFolder.cs#L150-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Create parent directories first; FluentFTP's CreateDirectory has an overload/force flag to create intermediates - use it.","Sanitize the desired name for the target server's allowed character set before calling CreateFolderAsync.","Check the FluentFTP reply (LastReply) for the MKD failure code and report it.","Verify the FTP account has directory-creation rights on the target path."],"exampleFix":"// before\nvar isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite, cancellationToken);\n\n// after - create the full path including parents\nvar isSuccessful = await ftpClient.CreateDirectory(newPath, overwrite || forceCreateParents: true, cancellationToken);\nif (!isSuccessful)\n    throw new IOException($\"Directory was not successfully created: {ftpClient.LastReply?.Code} {ftpClient.LastReply?.Message}\");","handlingStrategy":"retry","validationCode":"// Ensure parent exists and name is valid before creating.\nif (!await ftpClient.DirectoryExists(parentPath, ct))\n    await ftpClient.CreateDirectory(parentPath, true, ct);\nif (desiredName.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)\n    throw new ArgumentException(\"Invalid directory name.\");","typeGuard":null,"tryCatchPattern":"try { return await folder.CreateFolderAsync(name, overwrite, ct); }\ncatch (IOException ex) when (ex.Message.Contains(\"not successfully created\"))\n{ var reply = ftpClient.LastReply; /* inspect and report */ throw; }","preventionTips":["Create parent directories first; FTP MKD is non-recursive.","Sanitize names for the target server's filesystem.","Inspect LastReply for the MKD failure code and report it."],"tags":["ftp","storage","folder-creation","network"],"backgroundTag":null,"analyzedSha":"68c68a58d4d6a5f7197e07c8fff85cfd4279c78b","analyzedAt":"2026-08-13T10:34:54.614Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}