The sheriff or jailer of the county in which the court is held, or of any county through which the inmate is required to pass, shall receive and safely keep the inmate in the county jail, during travel and attendance, if required to do so by the persons in charge of the inmate, for which they shall be allowed the legal charge for keeping inmates.