Foreigners have to pay for rail tickets in hard currency, preferably US Dollars, but it is still a cheap option by Western standards. Uzbekistan has road connections to all its neighbours. The border between Afghanistan and Uzbekistan is closed to all except Uzbek and Afghan nationals. Travellers should exercise caution around the Kyrgyz-Uzbek border as some violent incidents have occured. Contact your local embassy for details.
Foreigners have to pay for tickets in hard currency.
The best place to look for these are at the long-distance bus and train stations. Ashgabat is 24 hours and to Khojand is 3 hours 30 minutes.