The capillary flow of a ferrofluid in a single cylindrical capillary tube and through a sandy porous medium under the action of a nonuniform magnetic field is studied experimentally. The dynamics of the capillary rise and the static case have been considered. It has been shown that the nonuniform magnetic field with upward directed gradient accelerates the capillary rise; contrary, the nonuniform magnetic field with downward directed gradient decelerates the capillary rise. Time dependences of the ferrofluid height and maximum reachable height of ferrofluid have been analyzed. The method of the study of ferrofluid capillary rise based on the use of magnetic measurements has been proposed. It has been demonstrated that porous material parameters can be extracted from the results of measurements of the inductances of the solenoid with porous medium inside and the small sensing coil within a single experiment.