Dwarves can build doors with only a ramp to access them because doors are open when they are installed. Dwarves can't install a floodgate that way. I've tried that several times in the past. They won't destruct a wall that way or, apparently, build one. I just now tried that. I am going to leave three floodgates on top of a wall, approachable only from ramps, outside my fortress. Two of the floodgates are backed by a wall and the other is backed by a walkable space not reachable from the ground. The next Vile Force of Darkness should bring me some trolls to test this.
Edit: Trolls in the next Vile Force of Darkness ignored the floodgates. Unknown whether this was because they could do nothing with them, or if it was because their attention was on the fortress entrance. I have now redone my entrance to incorporate this test, so they must destroy the floodgates in order to enter. Waiting now, for the next seige ...
Edit #2: Next seige was a dragon, who was attempting to destroy my open floodgates when I closed them. He was thereafter not able to access them and moved away from the entrance. He did appear to be standing on the ramp when he was attempting to destroy them but was apparently unable to continue his effort after the ramp became his only access to the floodgates. When the floodgates were once again opened, he proceeded to destroy them (after burning up an Elven caravan en route to the depot).
My conclusion is that it works, for closed floodgates. Perhaps it will work for locked doors also.
Edit #3: It works for locked doors, also.
Edit #4: It does work, but appears not to, if there is an open path to the back side of the door. When both the floodgates and the door were closed, the trolls showed no interest in them. Before I had locked the door, one was trying to destroy it, but stopped when I locked it. They wandered off. I opened the floodgates. They returned. They began destroying both the floodgates and the locked door, standing apparently on the ramps. However, they could have accessed them from the same level if they had moved a few squares. I believe this is similar to Dwarves appearing to build on the diagonal when they can reach the site from an orthogonal position. The game is not violating the rules, but it is displaying a wrong configuration. These trolls could not access the locked door and closed floodgates without being able to reach them from the same level, but once that was possible they destroyed them from a position on the ramps, without moving to the same level. For Dwarven construction this is not very important, but if you had archers stationed down a corridor where the trolls should have been standing, this would be more important. Whether this bug also operates if the open path happens to run the full length of your fortress rather than a few steps into a corridor, I don't know.