Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
sftpget.zsh
Go to the documentation of this file.
1 #! /usr/bin/env zsh
2 ## ------------------------------------------------------------------------------------------
3 ##
4 ## Utils to get and upload files on sftp
5 ##
6 ## ------------------------------------------------------------------------------------------
7 
8 #!/bin/zsh
9 script=${0##*/}
10 
11 source ${0%${script}}ulib.sh
12 
13 if do_usage $*; then
14  usage "$script file_path/filename"\
15  "\nUtility script to get files from sftp, for example, \"$script singularity/irods_v3.3.1.sif\""
16 fi
17 
18 case $# in
19  1) ;;
20  *) fatal "Wrong number of arguments."
21 esac
22 
23 notice `which ${script:r}` ${1}
24 
25 export WGET_MAX_ATTEMPTS=5
26 
27 FILENAME=${1}
28 wget --no-check-certificate -q sftp.km3net.de/${FILENAME}.md5 -O ${FILENAME:t}.md5
29 
30 if [ -s ${FILENAME:t}.md5 ]; then
31 
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
36  WGET_ATTEMPT=0
37  else
38  echo "WARNING: download failed, retrying"
39  cat ${FILENAME:t}.md5
40  md5sum ${FILENAME:t}
41  let WGET_ATTEMPT=WGET_ATTEMPT-1
42  fi
43  done
44 
45  if md5sum --status -c ${FILENAME:t}.md5; then
46  echo "file download and check OK!"
47  rm ${FILENAME:t}.md5
48  fi
49 
50 else
51  echo "WARNING: MD5 file is not avilable or empty"
52  rm ${FILENAME:t}.md5
53  wget -q sftp.km3net.de/${FILENAME} -O ${FILENAME:t}
54 fi