ftp problem

I use FTP in a shell script to transfer the files to a remote server.
Sometimes the program hangs without returning any errors
after the command

ftp server_name

How do you detect from within the shell that something is wrong?
How do you trap the errors returned by ftp command?

Any help will be greatly appreciated.

marusia

If it is hanging there it is usually a network issue (slow network, routes not there, too many hops...), a server issue (server is down or non-responsive). If you attempt to ping the server before doing the ftp to the server you may be able to stop it from hanging because of the problems listed. I just tried to ftp to a server I decommissioned and it took 5 minutes for it to come back to tell me that there is no route to host...but it's still trying!

What you are suggesting is actually what I tried to do - use ping command. The result was:

no answer from server_name

Meanwhile the ftp worked this time around.
Any other suggestions?

marusia

You can put a loop into your script (along with a timer if needed) to keep trying the ping - once it's successful, do the ftp session.
The timer is just in case you don't want it to keep going forever.
All you do is set up a counter and use the sleep command - your code will be different....

sleep 120
@ now = $now + 2
if ($now > 60) then
# send email stating it hit the timeout of one hour
exit
else
keep checking...

I'm sure others will have different ideas.