The Morocco Guide
It is possible but very rushed. The train takes about 6.5 hours between the two. I would recommend choosing one city and exploring the surrounding day trips instead.