Takes around 90 mins, if the connecting bus at Albufeira is prompt .... no direct buses ... and most connections aren`t great ... so aim for 2 hours. Be better to take a taxi to Loule station and the train (70 min) ...
here is the bus times ... return table on same site http://algarvebus.info/002w.htm
Do-able as pyrman says but the problem may be coming back. The last weekday bus from Portimão to Albufeira is at 1840hrs and I have observed that if it is late at Albufeira the last bus to Quarteira due out at 1930hrs does not necessarily wait.
At weekends, due to the general lack of buses, the latest you can leave Portimão for Quarteira by bus is at 1640!
There are buses between Quarteira and a stop not far from Loulé station that run about once each hour but they leave you a walk of about 250 metres including a rather dingy alleyway.