2## ------------------------------------------------------------------------------------------
 
    4##                         Utils to get and upload files on sftp
 
    6## ------------------------------------------------------------------------------------------
 
   11source ${0%${script}}ulib.sh
 
   14    usage "$script  file_path/filename"\
 
   15          "\nUtility script to get files from sftp, for example, \"$script singularity/irods_v3.3.1.sif\""
 
   20    *)  fatal "Wrong number of arguments."
 
   23notice `which ${script:r}` ${1}
 
   25export WGET_MAX_ATTEMPTS=5
 
   28wget --no-check-certificate -q sftp.km3net.de/${FILENAME}.md5 -O ${FILENAME:t}.md5
 
   30if [ -s ${FILENAME:t}.md5 ]; then
 
   32        WGET_ATTEMPT=$WGET_MAX_ATTEMPTS
 
   33        while [[ $WGET_ATTEMPT != 0 ]]; do
 
   34                wget -q sftp.km3net.de/${FILENAME} -O ${FILENAME:t}
 
   35                if md5sum --status -c ${FILENAME:t}.md5; then
 
   38                        echo "WARNING: download failed, retrying"
 
   41                        let WGET_ATTEMPT=WGET_ATTEMPT-1
 
   45        if md5sum --status -c ${FILENAME:t}.md5; then
 
   46                echo "file download and check OK!"
 
   51        echo "WARNING: MD5 file is not avilable or empty"
 
   53        wget -q sftp.km3net.de/${FILENAME} -O ${FILENAME:t}