The script below is written to ftp files to different directories on the destination server, but I'm not sure whether I have written the code correctly or not.
(
echo "
open ${SERVER}
user ${USERID} ${PASSWD}
for folder in ${FOLDER}; do
cd ${folder}
COUNT=1;
for filename in ${FILE_NAMES}; do
if [ ${COUNT} -eq ${DIRECTORY} ]; then
put ${filename}
break;
fi
COUNT=`expr $COUNT + 1`
done
DIRECTORY=`expr $DIRECTORY + 1`
done
close
"
) | ftp -i -n
if [ $? -ne 0 ]; then
echo "File Upload Failed"
else
echo "File Upload Completed"
fi
Not gonna fly. You cannot echo sh statements into a ftp client. The ftp client knows "open" and "user" , so that makes sense. But you can't type "for" loops into an ftp client. So you can't echo a "for" loop in either and expect it to work. To see my solution to this sort of thing, navigate:
our home page -> Answers to Frequently Asked Questions -> Automate FTP / Scripting FTP Transfers -> For Loops Within Ftp Comands
Um...who's Jim? The code looks good, but why not try it? That's how I determine if code works or not.
Checking the return code does not work. The ftp clients seem to return 0 if the connection attempt was successful. You could cd to a second local directory and run a second ftp job to retrieve the files you just transferred. Then compare the retrieved files with the original files. This would be expensive if the files are large. You could also use the ftp dir command and parse the output. This is quite a chore but the recursive ftp script linked in that faq article shows how I did it.
I tried your script and it worked for me....mostly. Either you have a bug or a very odd directory structure.
After you do
print -p cd $job2
after the first iteration through the loop, you are in the 3t subdirectory. The next time you will be in 3t/11 then in 3t/11/12 and so on.
Maybe you want a
print -p cd ..
or maybe not... who knows?
But this is not a "connection timeout". Can you ftp manually to the host in question? I would expect that to fail too.