Sailing upriver is difficult but possible. A sailing ship cannot sail directly into the wind. A fore-and-aft rig might be able to get 4 points (45deg) from the wind, but that's about it. Most rivers wind around, so if you hit a stretch where the wind and river line up, you'll be tack upon tack every few minutes. To make matters worse, the wind tends to follow the river valley in many places. If the river is wide enough, and the boat small enough, it can be done. Avoiding things like sandbars and other ships would be a major problem. Essentially, you would sail as close to the wind as possible (tacking) until you get to one bank of the river, then turn around (tack) and sail towards the other bank, again as close to the wind direction as your boat allows. You zig-zag your way upriver.
There are two common solutions to the problem, depending on the level of infrastructure in place. The most common would be to simply row upstream. A dedicated river boat would have a crew of rowers, but many sailing vessels would have provisions for mounting oars. Otherwise, a larger sailing ship, if you needed to take it upriver, could lower the ship's boats and have them tow the ship.
The second solution is to tow the boat from shore. The Romans constructed pathways along the riverbank so that oxen or men (Helciarri) could pull the boats upstream. This was done along a number of rivers, most notably from the port at Ostia to Rome along the Tiber River. The British adopted this method along their extensive canal system, some of which still exist. Here's a video of one.