{"record":{"id":"fe1e5088bbf1dace","repo":"files-community/Files","slug":"failed-to-connect-to-ftp-server-fe1e50","errorCode":null,"errorMessage":"Failed to connect to FTP server.","messagePattern":"Failed to connect to FTP server\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs","lineNumber":241,"sourceCode":"\t\t\t\t\t\tthrow new FileAlreadyExistsException(desiredName);\n\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tthrow new IOException($\"Failed to create file {remotePath}.\");\n\t\t\t}, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync));\n\t\t}\n\n\t\tpublic override IAsyncOperation<BaseStorageFolder> CreateFolderAsync(string desiredName)\n\t\t\t=> CreateFolderAsync(desiredName, CreationCollisionOption.FailIfExists);\n\t\tpublic override IAsyncOperation<BaseStorageFolder> CreateFolderAsync(string desiredName, CreationCollisionOption options)\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{\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}\"));","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/files-community/Files/blob/68c68a58d4d6a5f7197e07c8fff85cfd4279c78b/src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs#L223-L259","documentation":"Thrown by FtpStorageFolder.CreateFolderAsync (Files.App/Utils) when EnsureConnectedAsync returns false - the client could not connect. Identical root cause to error 10 but on the folder-creation path; runs inside SafetyExtensions.Wrap with RetryWithCredentialsAsync.","triggerScenarios":"CreateFolderAsync where EnsureConnectedAsync fails before the DirectoryExists/CreateDirectory calls. Wrong credentials, unreachable host, blocked port, or failed TLS handshake.","commonSituations":"Expired stored password; server downtime; firewall blocking control/data ports; cert trust change; stale client in a pool.","solutions":["Trigger the credentials retry path (RetryWithCredentialsAsync) to re-prompt the user.","Verify host/port/encryption configuration matches the server.","Check network and firewall reachability to the FTP control and passive data ports.","Catch IOException and classify it as a connection failure for user messaging.","Recreate the folder handle from a fresh connection if the client is stale."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Confirm connectivity before creating the folder.\nusing var c = GetFtpClient();\nif (!await c.EnsureConnectedAsync())\n    throw new IOException(\"Cannot reach FTP server; check credentials and network.\");","typeGuard":null,"tryCatchPattern":"try { await folder.CreateFolderAsync(name, options); }\ncatch (IOException ex) when (ex.Message.Contains(\"connect to FTP\"))\n{ /* re-prompt credentials, then retry */ }","preventionTips":["Re-prompt credentials via the RetryWithCredentialsAsync hook.","Verify host/port/encryption configuration.","Confirm firewall allows control and passive data ports."],"tags":["ftp","storage","folder-creation","network","connection"],"backgroundTag":null,"analyzedSha":"68c68a58d4d6a5f7197e07c8fff85cfd4279c78b","analyzedAt":"2026-08-13T10:34:54.614Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}