while loop to copy on failure

I'm trying to do an automated SCP (passwordless auth is already set up) from a bash script...

My problem is that on the receiving end, the computer will sometimes NOT actually get my files. BUT if I loop enough times (by hand at the moment) calling an 'ls' on those files, I can see if the files got there, otherwise resend.

This works, believe it or not... maybe somethings screwed up with my SCP?

Either way, I want to now put this functionality into a script, so I can just get the 'ls' of my files, see if there are 4 lines (pre-grepped for just files, no headers) -- aka 4 files -- and if there are, continue... else loop.

Pseudo-code:

do {
  scp veryOriginalName.1 root@myComp:/tmp
  scp veryOriginalName.2 root@myComp:/tmp
  scp veryOriginalName.3 root@myComp:/tmp
  scp veryOriginalName.4 root@myComp:/tmp

  VAR = ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l
} while {
  VAR != 4
}

If I understand the problem correctly :confused:, for kourne-shell, can do something like below:

#!/bin/ksh

file_cntr=0
while [[ $file_cntr != 4 ]]; do
# do copy file
scp ...

# do get file_cntr value
file_cntr=`ssh root@myComp "ls -l ...`
done

Why not use the error code returned by scp to indicate the success or failure of the operation?

Also, you can transfer multiple at the same time which would save time on connection and negotiation....

scp veryOriginalName.1 \
       veryOriginalName.2 \
       veryOriginalName.3 \
       veryOriginalName.4 root@myComp:/tmp/
if test "$?" = "0"
then
     echo success
     VAR = `ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l`
else
     echo failure
fi