{"record":{"id":"da33f12835f89ce8","repo":"files-community/Files","slug":"failed-to-create-folder-desiredname","errorCode":null,"errorMessage":"Failed to create folder {desiredName}.","messagePattern":"Failed to create folder (.+?)\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs","lineNumber":256,"sourceCode":"\t\t\t\tusing var ftpClient = GetFtpClient();\n\t\t\t\tif (!await ftpClient.EnsureConnectedAsync())\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException($\"Failed to connect to FTP server.\");\n\t\t\t\t}\n\n\t\t\t\tstring fileName = $\"{FtpPath}/{desiredName}\";\n\t\t\t\tif (await ftpClient.DirectoryExists(fileName))\n\t\t\t\t{\n\t\t\t\t\tvar item = new FtpStorageFolder(new StorageFileWithPath(null, fileName));\n\t\t\t\t\t((IPasswordProtectedItem)item).CopyFrom(this);\n\t\t\t\t\treturn item;\n\t\t\t\t}\n\n\t\t\t\tbool replaceExisting = options is CreationCollisionOption.ReplaceExisting;\n\t\t\t\tbool isSuccessful = await ftpClient.CreateDirectory(fileName, replaceExisting, cancellationToken);\n\t\t\t\tif (!isSuccessful)\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException($\"Failed to create folder {desiredName}.\");\n\t\t\t\t}\n\n\t\t\t\tvar folder = new FtpStorageFolder(new StorageFileWithPath(null, $\"{Path}/{desiredName}\"));\n\t\t\t\t((IPasswordProtectedItem)folder).CopyFrom(this);\n\t\t\t\treturn folder;\n\t\t\t}, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync));\n\t\t}\n\n\t\tpublic override IAsyncOperation<BaseStorageFolder> MoveAsync(IStorageFolder destinationFolder)\n\t\t\t=> MoveAsync(destinationFolder, NameCollisionOption.FailIfExists);\n\t\tpublic override IAsyncOperation<BaseStorageFolder> MoveAsync(IStorageFolder destinationFolder, NameCollisionOption option)\n\t\t{\n\t\t\treturn AsyncInfo.Run((cancellationToken) => SafetyExtensions.Wrap<BaseStorageFolder>(async () =>\n\t\t\t{\n\t\t\t\tusing var ftpClient = GetFtpClient();\n\t\t\t\tif (!await ftpClient.EnsureConnectedAsync())\n\t\t\t\t\tthrow new IOException($\"Failed to connect to FTP server.\");\n","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/files-community/Files/blob/68c68a58d4d6a5f7197e07c8fff85cfd4279c78b/src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs#L238-L274","documentation":"Thrown by FtpStorageFolder.CreateFolderAsync (Files.App/Utils) when AsyncFtpClient.CreateDirectory returns false. The directory could not be created at {FtpPath}/{desiredName}: usually a missing parent directory (FTP MKD is non-recursive), lack of create permission, invalid name, or the server rejecting the operation.","triggerScenarios":"CreateDirectory(fileName, replaceExisting, ct) returning false after a successful connection and after the DirectoryExists early-return did not apply. Missing parent is the most common cause when creating nested paths in one step.","commonSituations":"Creating nested folders without creating parents first; accounts restricted below the target; names with illegal characters; servers that disallow overwriting an existing directory.","solutions":["Create parent directories first, or use a recursive create that forces intermediate directory creation.","Sanitize the desired name for the target server's filesystem.","Check ftpClient.LastReply for the MKD failure code and report it.","Confirm the FTP account has directory-creation rights on the target.","Catch IOException and retry once after ensuring the parent exists."],"exampleFix":"// before\nbool isSuccessful = await ftpClient.CreateDirectory(fileName, replaceExisting, cancellationToken);\n\n// after\nbool isSuccessful = await ftpClient.CreateDirectory(fileName, replaceExisting || forceParents: true, cancellationToken);\nif (!isSuccessful)\n    throw new IOException($\"Failed to create folder {desiredName}: {ftpClient.LastReply?.Code} {ftpClient.LastReply?.Message}\");","handlingStrategy":"try-catch","validationCode":"// Ensure the parent directory exists before creating a nested folder.\nif (!await ftpClient.DirectoryExists(FtpPath, ct))\n    await ftpClient.CreateDirectory(FtpPath, true, ct);","typeGuard":null,"tryCatchPattern":"try { return await folder.CreateFolderAsync(name, options); }\ncatch (IOException ex) when (ex.Message.Contains(\"Failed to create folder\"))\n{ var reply = ftpClient.LastReply; /* inspect and report MKD failure */ throw; }","preventionTips":["Create parent directories first; FTP MKD is non-recursive.","Sanitize the name for the target server's filesystem.","Inspect LastReply for the 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"}