Sometimes when I try to use curl to upload to an ftp server, I get the message:
$curl -T file.wmv ftp.eu.filesonic.com --user user:password
curl: (8) Got a 421 ftp-server response when 220 was expected
How do I get the script to try again if I get the message curl: (8)?
How about the curl "retry" option?
curl returns an non-zero exit status when you get an error and a zero exit status when it works so to handle it in the shell, try...
while ! curl -T file.wmv ftp.eu.filesonic.com --user user:password
do
sleep 1
done
The sleep's there just to stop it going off into a rapid loop! See the curl man page for a full list of error codes
Jerry
Pretty much the same as Jerry's solution, just in script form with some extra text and what not.
(20:18:15\[D@DeCoWork15)
[~]$ cat help
upload ()
{
curl -T ${1} ftp.eu.filesonic.com --user user:password
}
if [[ -z $1 ]];then
echo "USAGE: $0 <file to upload>"
exit 1
fi
while true;do
upload ${1}
if [[ ${?} -ne 0 ]];then
upload
else
echo "$1 uploaded successfully"
exit 0
fi
done