Fair-weather friend

A person who is a friend only during good times.

The man is a fair-weather friend and you cannot rely on him if you have a problem.