{"record":{"id":"4ec59bfe6dc5fd68","repo":"files-community/Files","slug":"file-creation-failed","errorCode":null,"errorMessage":"File creation failed.","messagePattern":"File creation failed\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Files.App.Storage/Ftp/FtpStorageFolder.cs","lineNumber":152,"sourceCode":"\t\t\t\tthrow new IOException(\"File already exists.\");\n\n\t\t\tusing var stream = new MemoryStream();\n\t\t\tvar result = await ftpClient.UploadStream(stream, newPath, overwrite ? FtpRemoteExists.Overwrite : FtpRemoteExists.Skip, token: cancellationToken);\n\n\t\t\tif (result == FtpStatus.Success)\n\t\t\t{\n\t\t\t\t// Success\n\t\t\t\treturn new FtpStorageFile(newPath, desiredName, this);\n\t\t\t}\n\t\t\telse if (result == FtpStatus.Skipped)\n\t\t\t{\n\t\t\t\t// Throw exception since flag CreationCollisionOption.GenerateUniqueName was not satisfied\n\t\t\t\tthrow new IOException(\"Couldn't generate unique name. File skipped.\");\n\t\t\t}\n\t\t\telse\n\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);","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/files-community/Files/blob/68c68a58d4d6a5f7197e07c8fff85cfd4279c78b/src/Files.App.Storage/Ftp/FtpStorageFolder.cs#L134-L170","documentation":"Thrown by FtpStorageFolder.CreateFileAsync when UploadStream returns a status that is neither Success nor Skipped - i.e. FtpStatus.Failed. This indicates FluentFTP could not complete the upload of the empty MemoryStream to {Id}/{desiredName}. Causes are server-side: permission denied, path does not exist, quota exceeded, or a broken/terminated control or data connection.","triggerScenarios":"UploadStream returning FtpStatus.Failed during CreateFileAsync. Typical when the parent directory is missing, the FTP user lacks write permission on the target folder, disk/quota limits are hit, or the connection dropped mid-transfer.","commonSituations":"Read-only or quota-capped FTP accounts; uploading into a path that was never created; TLS/data-port firewall rules that intermittently break PASV transfers; anti-virus blocking zero-byte file creation on the server.","solutions":["Inspect the FluentFTP log (FtpTrace or a custom logger) for the underlying 4xx/5xx reply to determine the real server-side cause.","Verify the FTP account has write permission and available quota on the target folder.","Ensure the parent directory exists before creating the file.","Retry on transient failures with backoff; surface a clearer message mapping the FluentFTP reply code to the user.","Switch to an active-mode or alternate PASV port range if data-channel setup is failing."],"exampleFix":"// before\nvar result = await ftpClient.UploadStream(stream, newPath, existsMode, token: cancellationToken);\nif (result != FtpStatus.Success && result != FtpStatus.Skipped)\n    throw new IOException(\"File creation failed.\");\n\n// after - capture the last reply for diagnostics\nvar reply = ftpClient.LastReply;\nthrow new IOException($\"File creation failed: {(int)reply.Code} {reply.Message}\");","handlingStrategy":"retry","validationCode":"// Verify writability of the target before the upload.\nif (!await ftpClient.FileExists(folder.Id, ct)) { /* ensure parent exists */ }","typeGuard":null,"tryCatchPattern":"for (int attempt = 0; attempt < 3; attempt++)\ntry { return await folder.CreateFileAsync(name, overwrite, ct); }\ncatch (IOException ex) when (ex.Message == \"File creation failed.\" && attempt < 2)\n{ await Task.Delay(TimeSpan.FromSeconds(1 << attempt)); }\nthrow new IOException(\"File creation failed after retries.\");","preventionTips":["Log ftpClient.LastReply to capture the server's 4xx/5xx reason.","Confirm write permission and quota on the target folder.","Ensure the parent directory exists before creating files."],"tags":["ftp","storage","file-creation","network"],"backgroundTag":null,"analyzedSha":"68c68a58d4d6a5f7197e07c8fff85cfd4279c78b","analyzedAt":"2026-08-13T10:34:54.614Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}