The only known cloning glitches in Gen 4 involve turning the DS off at the correct time while a Pokemon is being traded or sent to the GTS. Of course, this technique is risky. The safest way to clone Pokemon is using third-party software like PKHeX (though you should know what you're doing with that, too).
There are no known cloning glitches in Gen 5. However, it is possible to make the GTS connect to a "custom server" by changing the DNS used by the DS. This custom server can theoretically offer cloning functionality.
Source