Shift Motor would be the first stop
You should shift into 4high then 4low and back to 2WD once a month, just sitting in the driveway, you don't have to move the vehicle.
What that does is to keep the electric motor contacts clean.
Often if it stops working you can "tap" on the motor to get it to move again, this gets the motors brushes, which get stuck, to touch rotor again and motor can get power.
A 2004 Ranger will use a separate 4x4 module to control the shift motor, and these did fail, not a common issue but not unheard of either.
Shift motor is the only "moving" part in the system except for the Relays in the 4x4 module.
Shift motor is a DC motor so the direction it will turn the transfer case shift rod is determined by polarity, + and - applied to the 2 motor wires, the 2 relays in the 4x4 module do this polarity change.
Shift motor set at 2WD will have to turn 90deg counter clockwise to get to 4high, then another 90deg to get to Neutral(yes there is a Neutral, you just can't select it

)
Then another 90deg counter clockwise to get to 4low
So 2WD to 4low is 270deg rotation counter clockwise, same polarity on motor.
To go back to 2WD, or 4high, from 4low you have to Reverse the motors polarity, so it moves Clockwise, 180deg to 4high or 270deg to 2WD
1 relay in the 4x4 module could go bad so motor only move counter clockwise, so you would get stuck in 4low, but it wouldn't be likely to start working again.
The 5 "extra wires" on the shift motor are for a contact wheel inside the gear drive of the shift motor, these contacts "tell" the 4x4 module when it gets to 4high, 4low or 2WD positions, this is adjustable somewhat by slotted bolt holes