how to connect to a list of IP by ftp in shell script

Hi everyone,
I have to maintenance an old script unix (#!bin/sh) that get files from remote host by ftp.
There is a configuration file that contains a list of IP; the script reads this file, one line by line, and per each IP execute these commands:

echo "verbose on" > ftprap.cmd
echo "prompt " >> ftprap.cmd
echo "ascii" >> ftprap.cmd
echo "mget * " >> ftprap.cmd
echo "quit" >> ftprap.cmd

ftp $IP < $PATH/ftprap.cmd

The problem is: if one host is not connected or unreachable, the scripts is locked and is enabled to connect to the other hosts (and so to get their files).
I try to resolve this problem using �ping -w 2 $IP� the host before connecting but because of the firewall, there are some hosts that block the ping but consent ftp.
I've looked for a timeout to apply to the ftp command but I've not found it.
There is someone who could help me? Thanks.

You could try using netcat to see if the port is open.

You could background the ftp (&), record the PID ($?), periodically check whether the background job has finished (jobs) in an escapable sleep loop (break), then after your timeout period has expired check whether the PID is still there (kill -0 PID) and then kill the PID if it is still there.

netcat doens't guarantee that the fpt works... it's ok about ftp & and kill (even if I don't like kil but it's the only way in this case).. it works.
Thanks guys!