In this article, we derive the formula for the Casimir force acting on a piston made of real material moving inside a perfectly conducting rectangular box. It is shown that by taking suitable limits, one recovers the formula for the Casimir force acting on a perfectly conducting piston or an infinitely permeable piston. The Lifshitz formula for finite temperature Casimir force acting on parallel plates made of real materials is re-derived by considering the five-layer model in the context of the piston approach. It is observed that the divergences of the Casimir force will only cancel under certain conditions, for example, when the regions separated by the plates are filled with media of the same refractive index.