No need to worry about the length of the line at all. A 5 ft or even shorter section will work just fine. The trick is to transfer from beer out to beer out. IOW, fill the keg through the beer out post. This way the receiving keg fills from the bottom up and minimizes foaming. The best way to do it is to first purge the receiving keg with CO2 to displace the air. Keep the receiving keg pressurized through the entire transfer. To start, have both kegs at the same low pressure of about 4-5 psi. The beer will not flow so long as both kegs are at the same pressure. Next, pull the pressure relief valve on the receiving keg. This will start the beer flowing. Release more pressure from the receiving keg as it slowly fills. You want to go fairly slow to minimize foaming. If the beer is cold, you can usually observe the "frost line" of condensation on the receiving keg and this lets you know how it's progressing. Some foaming will inevitably occur. If foam begins to come out of the pressure relief valve on the receiving keg, simply stop the transfer for 10 minutes or so to give it time to settle down, then resume the transfer. Some foam will come out the pressure relief valve as you near completion of the transfer and the fuller the keg is the more foam you will get. This is not a big deal, just be prepared for it and have the keg in a tub or on a towel to minimize the mess. You can do all of this at a very slow rate and generate little or no foam, but I'm not that patient. The transfer should take about 15-20 minutes going fairly slow and that works for me.
Oh yeah, take care that the receiving keg pressure does not exceed the donor keg pressure when connected as this can result in beer backing up into the donor keg which will churn up the yeast and stuff that has settled out in the fermenter. The result will be cloudy beer. It's also a good idea to be very gentle when moving the donor keg in order to avoid the same thing. I like to make the transfer without moving the donor keg at all. Do it that way if you can.