This process is known as electro-refining. It is one of the best methods known for producing metals of high purity.
In this process, the desired metal with impurities is taken as the anode and a pure metal is taken as the cathode. We select an electrolyte with the same metallic ions.
When an electric potential greater than the cell potential is applied across the two electrodes, the metallic ions from the impure metal at the anode side are oxidized and pass into solution. And the metallic ions present in the electrolyte solution get reduced and get deposited on the cathode.