Re: Script that checks for existence of file on remote server. steven_nospam at Yahoo! Canada <steven_nospam@yahoo.ca> wrote:
> If you are going to use FTP, here's a method that may work:
>
> ftp -i ${DESTHOST} << END >> ${TMPOUT}
>
> BYTES_SENT=$(cat ${TMPOUT} | grep "bytes sent" | cut -f1 -d ' ')
> BYTES_ORIG=$(ls -l $(SRCFILE} | awk '{ print $5 }')
>
> if test "${BYTES_SENT}" = "${BYTES_ORIG}"
> then
> echo "File is same size on remote host - successful transfer"
> else
> echo "File sizes differ:"
> fi
>
> Of course, I'm not sure if the size on the remote is ALWAYS going to be
> the same as on the local system. That is something you'd have to
> evaluate.
One way to make sure that the size on the destination system will be the
same is to use binary mode file transfer.
If you have to transfer ASCII files, and the destination system does not
run UNIX, you will need ascii mode file transfer.
You can force binary mode by issuing 'binary' before the 'put' command
and ascii mode by issuing 'ascii'.
If you use ascii file transfer, the size of the file on the receiving end
could be different; e.g. if you transfer from UNIX to Windows, an
ASCII 0x0d character (carriage return) will be inserted before every
line feed (ASCII 0x0a), thereby enlarging the destination file.
In that case I see two possibilities:
a) forget about the file size and check the output file for the message
that indicates successful transfer.
b) convert the file to the correct ascii format on the destination
platform first and then transfer it in binary mode. For UNIX to Windows
transformation, you could use the 'doswrite' command that is shipped
with AIX.
Yours,
Laurenz Albe |